Skip to main content

Shared Anchor State

Throughout the relocalization process, you can query the current state of shared anchor from ARSharedAnchorManager.RelocalizationState. You can also listen to an event for every shared anchor state changes. A shared anchor can be in one of these states:

public enum RelocalizationState
{
Stopped = 0,
Initializing = 1,
Relocalizing = 2,
Relocalized = 3
}

// ARSharedAnchorManager.cs

// Get the current shared anchor state
public RelocalizationState RelocalizationState { get; }

// Attach a callback to this event to listen on shared anchor state changes.
public delegate void RelocalizationStateChanged(RelocalizationState newState);
public event RelocalizationStateChanged OnRelocalizationStateChanged;

Usage Example

[SerializeField]
private ARSharedAnchorManager _sharedAnchorManager;

private void Update()
{
// Use the RelocalizationState to update a UI Text e.g.,
// _statusLabel.text = _sharedAnchorManager.RelocalizationState.ToString();
}

Alternatively use the event:

[SerializeField]
private ARSharedAnchorManager _sharedAnchorManager;

private void OnEnable()
{
// Subscribe to event
_sharedAnchorManager.OnRelocalizationStateChanged += UpdateStatusLabel;
}

private void OnDisable()
{
// Unsubscribe to event
_sharedAnchorManager.OnRelocalizationStateChanged -= UpdateStatusLabel;
}

private void UpdateStatusLabel(RelocalizationState newState)
{
// Update a UI Text with current state e.g.,
// _statusLabel.text = newState.ToString();
}