Skip to main content

Handling Successful Relocalization

You can listen to OnRelocalized event for when relocalization is successful.

// ARSharedAnchorManager.cs

// Attach a callback to this event to listen for successful relocalization
public delegate void RelocalizedEvent();
public event RelocalizedEvent OnRelocalized;

// Alternatively, you can attach a callback to specific map relocalization events
public delegate void MapRelocalizationEvent(string mapKey);
public event MapRelocalizationEvent OnMapRelocalizationStarted;
public event MapRelocalizationEvent OnMapRelocalized;

// or image relocalization events
public delegate void ImageRelocalizationEvent(XRReferenceImage referenceImage);
public event ImageRelocalizationEvent OnImageRelocalizationStarted;
public event ImageRelocalizationEvent OnImageRelocalized;

Usage Example

[SerializeField]
private ARSharedAnchorManager _sharedAnchorManager;

private void OnEnable()
{
// Subscribe to event
_sharedAnchorManager.OnRelocalized += ShowContent;
_sharedAnchorManager.OnMapRelocalized += ShowContentByMapKey;
_sharedAnchorManager.OnImageRelocalized += ShowContentByReferenceImage;
}

private void OnDisable()
{
// Unsubscribe to event
_sharedAnchorManager.OnRelocalized -= ShowContent;
_sharedAnchorManager.OnMapRelocalized -= ShowContentByMapKey;
_sharedAnchorManager.OnImageRelocalized -= ShowContentByReferenceImage;
}

private void ShowContent()
{
// Do something to show your content e.g.,
// contentGameObject.SetActive(true);
}

private void ShowContentByReferenceImage(XRReferenceImage referenceImage)
{
// Do something to show your content depending on the reference image e.g.,
// contentGameObject.SetActive(true);
}

private void ShowContentByMapKey(string mapKey)
{
// Do something to show your content depending on the map key e.g.,
// contentGameObject.SetActive(true);
}