13

I'm currently doing some experiments with RealityKit.

I've been looking at some sample code, and I'm a bit confused about the differences between ARAnchor and AnchorEntity, and when to use one over the other.

So far I know that:

  • Both are anchors that describes a position in the real world.
  • AnchorEntity can also have other Entity's as children, so you can add model objects directly to the anchor. You can't do this with ARAnchor, you have to add model objects "manually" to the rootNode, and use the position of the anchor the place it correctly.
  • In the documentation it says that ARKit uses the added ARAnchor to optimize the tracking in the area around the anchor. The documentation for AnchorEntity does not specify this.

Right now I add a AnchorEntity to the session as a "root node", since it's simpler to use, so that I can simply add models as children directly to this anchor. But then I also add a ARAnchor, located at the same position, to the scene's anchors, to enhance tracking around this point. Is this nececary?

Q: Anyone can help me clarify the differences, and use cases of these two?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
eivindml
  • 2,197
  • 7
  • 36
  • 68

1 Answers1

22

Updated: July 18, 2023.


ARAnchor and AnchorEntity classes were both made for the same divine purpose – to tether 3D models to your real-world objects.

RealityKit AnchorEntity greatly extends the capabilities of ARKit ARAnchor. The most important difference between these two is that AnchorEntity automatically tracks a real world target, but ARAnchor needs session(...) instance method (or SceneKit's renderer(...) instance method) to accomplish this. Take into consideration that the collection of ARAnchors is stored in the ARSession object and the collection of AnchorEntities is stored in the Scene.

In addition, generating ARAchors requires a manual Session config, while generating AnchorEntities requires minimal developer's involvement.

Hierarchical differences of iOS AR scenes:

enter image description here

The main advantage of RealityKit is the ability to use different AnchorEntities at the same time, such as .plane, .body or .object. There's automaticallyConfigureSession instance property in RealityKit. When enabled, the ARView automatically runs an ARSession with a config that will get updated depending on your camera mode and scene anchors. When disabled, the session needs to be run manually with your own config.

arView.automaticallyConfigureSession = true           // default

In ARKit, as you know, you can run just one config in the current session: World, Body, or Geo. There is an exception in ARKit, however - you can run two configs together - FaceTracking and WorldTracking (one of them has to be a driver, and the other one – driven).

let config = ARFaceTrackingConfiguration()
config.isWorldTrackingEnabled = true
arView.session.run(config)


Apple Developer documentation says:

In RealityKit framework you use an AnchorEntity instance as the root of an entity hierarchy, and add it to the anchors collection for a Scene instance. This enables ARKit to place the anchor entity, along with all of its hierarchical descendants, into the real world. In addition to the components the anchor entity inherits from the Entity class, the anchor entity also conforms to the HasAnchoring protocol, giving it an AnchoringComponent instance.

AnchorEntity has three building blocks:

  • Transform component (transformation matrix containing translate, rotate and scale)
  • Synchronization component (entity's synchronization data for multiuser experience)
  • Anchoring component (allows choose a type of anchor – world, body or image)


All entities have Synchronization component that helps organise collaborative sessions.

enter image description here


AnchorEntity has the eleven specific anchor types for eleven different purposes:

  • ARAnchor
    • helps implement 10 ARKit anchors, including ARGeoAnchor and ARAppClipCodeAnchor
  • body
  • camera
  • face
  • image
  • raycastResult
  • object
  • plane
  • world
  • head
    • (works in visionOS only)
  • hand
    • (works in visionOS only)


You can simultaneously use both classes ARAnchor and AnchorEntity in your app. Or you can use just AnchorEntity class because it's all-sufficient one.

For more info on ARAnchor and AnchorEntity, please read THIS POST.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 2
    Thank you for very good explanation! But what about this: _"In the documentation it says that ARKit uses the added ARAnchor to optimize the tracking in the area around the anchor. The documentation for AnchorEntity does not specify this."_ ? Will AnchorEntity also do this optimization, or should I add both anchor types at the location my object will be placed to achieve best results? – eivindml Aug 28 '19 at 17:19
  • 2
    (Sorry @eivindml, I haven't noticed your comment earlier) You do not need to add both types of anchors in your scene. You need just one type: ARKit's ARAnchor or RealityKit's AnchorEntity. Anchors from both modules not only optimise the tracking but also make objects pinned to them more stable. – Andy Jazz Jan 08 '20 at 11:43
  • 1
    Do you know if when initializing an AnchorEntity with the constructor AnchorEntity(anchor: ARAnchor) if the AnchorEntity follows ARAnchor updates? – Nativ Nov 10 '20 at 15:07
  • Hi @Nativ, yes it follows when you use `session()` methods for ARAnchor. – Andy Jazz Nov 11 '20 at 12:21
  • Thanks for the reply @AndyFedoroff. Which methods do you mean? once you add a new ARAnchor you cannot change it, just monitor its updates or removal from the session – Nativ Nov 12 '20 at 07:46
  • session(_:didUpdate:) – Andy Jazz Nov 12 '20 at 10:44