Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved AR Image Tracking - Changing tracking set during runtime

Discussion in 'AR' started by rtilton1, Aug 5, 2020.

  1. rtilton1

    rtilton1

    Joined:
    Jan 4, 2017
    Posts:
    62
    On the ARTrackedImageManager script - is it possible to change which tracking set (SerializedLibrary variable) is used at runtime?

    I've tried:
    Code (CSharp):
    1. [SerializeField] ARTrackedImageManager trackedImageManager;
    2. [SerializeField] XRReferenceImageLibrary otherlib;
    3.  
    4. //later in code triggered on a button press
    5. 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.
     
    Last edited: Aug 5, 2020
  2. rtilton1

    rtilton1

    Joined:
    Jan 4, 2017
    Posts:
    62
    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:
    Code (CSharp):
    1. ARTrackedImageManager manager;
    2. manager.referenceLibrary = myReferenceImageLibrary;
     
  3. fjc

    fjc

    Joined:
    Oct 29, 2014
    Posts:
    1
    is this work for ios?
     
  4. thomas_key

    thomas_key

    Unity Technologies

    Joined:
    Dec 14, 2019
    Posts:
    39
    Yes, ARKit has support for MutableRuntimeReferenceImageLibrary.