SpatialEntity.CreateAnchor
static SpatialEntity CreateAnchor(Pose pose, string name, SpatialEntity parent)
Create a spatial anchor entity at the given pose, a
point the system will keep aligned with the physical world as
tracking improves or drifts. You can call this any time after
requesting SpatialCapability.Anchor, even while it’s still
starting up! Until the system takes over, the anchor sits at
this pose with Tracked inactive and Status Pending. If the
system can’t create it, the anchor shows up in Removed with
Status Failed.
| Pose pose | A world space pose for the new anchor. |
| string name | Persists the anchor under this name, so FindAnchor can get it back in a later session. Any anchor that already has this name is destroyed, so placing “table” again moves it. Leave this null for an anchor that only lasts this session, or call Persist later to keep it by Guid instead. |
| SpatialEntity parent | An optional entity to attach the anchor to, so it follows that entity as it moves. Few runtimes support this yet, and creation fails on those that don’t. |
| RETURNS: SpatialEntity | The new anchor entity. This is an invalid entity if this system doesn’t support anchors, or can’t persist them when given a name, so check Valid. |
Examples
Anchors that survive an app restart
Give an anchor a name, and FindAnchor gets it back in a later
session. Placing it again under the same name replaces the old one.
SpatialEntity anchor;
public void LoadAnchor()
{
Spatial.Request(SpatialCapability.Anchor);
anchor = SpatialEntity.FindAnchor("my_anchor");
}
// Call this from a button, a pinch, or wherever the user places content
public void PlaceAnchor(Pose pose)
=> anchor = SpatialEntity.CreateAnchor(pose, "my_anchor");
public void StepAnchor()
{
if (anchor.Tracked.IsActive())
Mesh.Cube.Draw(Material.Default, anchor.Pose.ToMatrix(0.1f));
}
Found an issue with these docs, or have some additional questions? Create an Issue on Github!