AR Shared Anchor Manager
ARSharedAnchorManager
is the MonoBehaviour
component responsible for managing shared anchor. We can start and stop relocalization from calling a method from this function. We can also query the various information that is available while doing relocalization, such as RelocalizationScore
. You will need to add this component on the same object as AR Foundation's ARSessionOrigin
component.
Inspector Settings
From the inspector, we can modify its behaviour. Let's look at what each of the parameters do.
Relocalize On Start
This option lets you use relocalization feature without writing a single line of code. If you enable this option, it will show additional parameters to modify its behaviour. These parameters are applied only if Relocalize On Start
is also enabled. At runtime, relocalization will start automatically with these parameters.
Restart Automatically On Error
When enabled, relocalization will restart automatically when it encounters any errors. If using map-based relocalization, then it will re-run the map selection strategy again.
Relocalization Type
You can choose from either Image
or Cloud Map
. It will use the assigned default parameter (Map Selection
for map-based relocalization, and Reference Image
for image-based relocalization) for each of its type.
Timeout In Milliseconds
You can set a timeout for how long it should attempt relocalization (in milliseconds). If set to 0
then it will attempt relocalization indefinitely until it succeeds or encounters an error.
Map-based Relocalization Default Parameter
Map Selection
This is used to set the default parameter used in map-based relocalization. It will be used if you enable Relocalize on Start
option, or when you call the API below without mapKey
as input. The SDK provides two default map selection strategy, which is DirectMapSelection
and CriteriaBasedMapSelection
(See Map Selection).
// ARSharedAnchorManager.cs
// Start map-based relocalization with the default parameter
public void StartCloudMapRelocalization(int timeoutInMilliseconds = 0);
// Start map-based relocalization to find the shared anchor in a map with mapKey
public void StartCloudMapRelocalization(string mapKey, int timeoutInMilliseconds = 0);
Image-based Relocalization Default Parameter
This is used to set the default parameter used in image-based relocalization. It will be used if you enable Relocalize on Start
option, or when you call the image-based reloc API without referenceImage
as input.
// ARSharedAnchorManager.cs
// Start image-based relocalization with the default parameter
public void StartImageRelocalization(int timeoutInMilliseconds = 0);
// Start image-based relocalization with the referenceImage as shared anchor when it's found
public void StartImageRelocalization(XRReferenceImage referenceImage, int timeoutInMilliseconds = 0);
AR Tracked Image Manager
Image-based relocalization uses AR Foundation underlying subsystem for image tracking. You need to add ARTrackedImageManager
component and assign a XRReferenceImageLibrary
to it. You can create a new reference image library by right-clicking on the Project
tab and select Create > XR > Reference Image Library
. Once you create it, you can add the images you want to use as the image marker.
Reference Image
After assigning the AR Tracked Image Manager
, this parameter will be enabled in the inspector, and you can choose which image to use as the shared anchor from the list of images in the reference image library assigned to the ARTrackedImageManager
component.