AR Image Tracking - Changing tracking set during runtime

On the ARTrackedImageManager script - is it possible to change which tracking set (SerializedLibrary variable) is used at runtime?

I’ve tried:

[SerializeField] ARTrackedImageManager trackedImageManager;
[SerializeField] XRReferenceImageLibrary otherlib;

//later in code triggered on a button press
trackedImageManager.subsystem.CreateRuntimeLibrary(otherlib);

But it always logs an error of a null reference for the CreateRuntimeLibrary line (I’m indeed setting the serialized fields in the inspector and have debugged both variables are set).

Looking into the ARTrackedImageManager script it seems there is an idea of an event for ’
trackedImagesChanged’, but I can’t seem to figure out how to actually change it at runtime myself.

Any advice would be greatly appreciated.

My buddy saved my day. Here’s the answer:

If you need to create a new library at runtime (to add generated images or new images at runtime) you’ll need to use a mutable reference image library. Some info in the docs here https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.0/manual/tracked-image-manager.html…

If you just changed it at runtime that should be fine as long as you’re referenced (assigned in the editor) library is not null and you can use:

ARTrackedImageManager manager;
manager.referenceLibrary = myReferenceImageLibrary;

is this work for ios?

Yes, ARKit has support for MutableRuntimeReferenceImageLibrary.