scene.addAnchor( ) vs scene.anchors.append( )

Hello Apple People,


Have a really basic question about the API of RealityKit.


Question:

Am I correct in that Realitykit has two ways to add an AnchorEntity to the scene.AnchorCollection?


First way would be:

Summary

Adds an anchor to the scene’s list of anchors.

Declaration

func addAnchor(_ anchor: HasAnchoring)


Second way would be:

Summary

No overview available.

Declaration

func append(_ entity: Scene.AnchorCollection.Element)


Observation:

If you "dig into the weeds of the Realitykit " API you will see this:

typealias Scene.AnchorCollection.Element = HasAnchoring


I believe one could think of the RealityKit code this way:

func append(_ entity: HasAnchoring)


I know this is a basic question, but Any Apple Devloper or kind soul intrested in helping a fellow Apple coder would be much apprecated.


We all learn by sharing what we know

Smartdog

Answered by maxxfrazer in 413531022

Hi,


Yes, using scene.anchors.append(myAnchor) has the same effect, and has the added bonus of being able to add multiple independent anchors at the same time by using scene.anchors.append(contentsOf: [Scene.AnchorCollection.Element]).


I don't know of any reason this should or should not need to be utilised. Only that to me, scene.addAnchor() seems like a nicer looking way to achieve the same thing, thus may be what the RealityKit team is expecting us to use.

Accepted Answer

Hi,


Yes, using scene.anchors.append(myAnchor) has the same effect, and has the added bonus of being able to add multiple independent anchors at the same time by using scene.anchors.append(contentsOf: [Scene.AnchorCollection.Element]).


I don't know of any reason this should or should not need to be utilised. Only that to me, scene.addAnchor() seems like a nicer looking way to achieve the same thing, thus may be what the RealityKit team is expecting us to use.

maxxfrazer,


I thank you for your insight.


maxxfrazer stated:

Yes, using scene.anchors.append(myAnchor) has the same effect, and has the added bonus of being able to add multiple independent anchors at the same time by using scene.anchors.append(contentsOf: [Scene.AnchorCollection.Element]).


very insightful indeed...Bingo!


I agrree scene.addAnchor() seem like the nice looking way to achive the same way. But I tend to like to read the code in long form, it helps me learn to "read" the API documentation.


P.S maxxfrazer :

please see updated information in form question about why frame set to zero in arkit.frame(.zero)

https://forums.developer.apple.com/thread/130614


Thank you again and have fun coding in RealityKit


We all learn by sharing what we know

Smartdog

scene.addAnchor( ) vs scene.anchors.append( )
 
 
Q