AuAnchor is the link between tracking and virtual content. Each anchor is associated with a Marker and automatically updates its transformation from the marker pose. As a result, anything added to the anchor inherits its placement in the world.
In a typical integration, markers are detected through Session.requestMarkers() in ARDK. Markers can be of different kinds, but in practice they are often visual patterns similar to QR-code-like drawings, designed to be recognized reliably by the tracking system.
When to use an anchor
Sezione intitolata “When to use an anchor”An anchor should be created when a marker needs to become the stable reference for one or more AR contents. In other words:
- the marker identifies where the content should appear;
- the anchor becomes the persistent node to which objects, groups, or panels are attached.
Creating an anchor from a marker
Sezione intitolata “Creating an anchor from a marker”When a marker is detected and attached by the tracking system, the application can create the corresponding AuAnchor and add it to the world:
val anchor = AuAnchor(marker)world.add(anchor)From that point on, the anchor is automatically updated during world.onDrawFrame().
Recommended flow when a marker is attached
Sezione intitolata “Recommended flow when a marker is attached”A clean application flow is:
- detect that a Marker has entered a state suitable for rendering;
- create an AuAnchor using the marker;
- add it to AuWorld;
- populate the anchor with the content associated with that marker.
This keeps two responsibilities clearly separated:
- tracking decides when the marker is available;
- the scene decides what content should appear on top of that marker.
Populating an anchor
Sezione intitolata “Populating an anchor”An anchor implements AuContainer, so it can directly contain scene entities:
val anchor = AuAnchor(marker)world.add(anchor)
val group = AuGroup()anchor.add(group)This is useful when the marker remains the main spatial reference, while the content itself is organized through its own hierarchy of groups, objects, and widgets.
Detaching and cleanup
Sezione intitolata “Detaching and cleanup”When the marker should no longer produce visible content, it is best to:
- remove the anchor from the world;
- close the native content created for that anchor, unless it is reused elsewhere;
- close the anchor itself.
This prevents native resources from staying alive after the related marker has effectively left the scene.
A practical rule of thumb
Sezione intitolata “A practical rule of thumb”It is helpful to think of AuAnchor as an application-level spatial support:
- the marker provides the pose;
- the anchor makes that pose available to the scene;
- the content relies on the anchor without needing to know the tracking layer directly.