Assign image tracking for co-localization at runtime

Include the following details (edit as applicable):

  • Issue category: Multiplayer
  • Device type & OS version: Android
  • Host machine & OS version: Windows
  • Issue Environment : On Device
  • ARDK version: 3.11
  • Unity version:2022.3.57f1

Description of the issue:

Is there a way to assign the image marker for tracking at runtime so that users can select a photo from their phone gallery and use it as the co-location anchor instead of an image that is added in the editor?

Right now I am trying with a texture and doing these modifications to the texture:

    Texture2D tImg = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false);
    tImg.SetPixels(texture.GetPixels());
    tImg.Apply();

    tartWidthPhysicalSize = physicalSize;

    // Adjust the texture settings
    tImg.filterMode = FilterMode.Bilinear;
    tImg.wrapMode = TextureWrapMode.Clamp;
    targetImage = tImg;
...

I then use this image to create the room

var imageTrackingOptions = ISharedSpaceTrackingOptions.CreateImageTrackingOptions(targetImage, tartWidthPhysicalSize);

This makes the tracking stop working, but it works with the image added on the editor

Actually I found this relevant error:

2025/02/26 18:08:29.483 23581 23601 Error Unity ArgumentNullException: Value cannot be null.
2025/02/26 18:08:29.483 23581 23601 Error Unity Parameter name: referenceImage.name
2025/02/26 18:08:29.483 23581 23601 Error Unity at UnityEngine.XR.ARSubsystems.MutableRuntimeReferenceImageLibrary.ValidateAndThrow (Unity.Collections.NativeSlice1[T] imageBytes, UnityEngine.Vector2Int sizeInPixels, UnityEngine.TextureFormat format, UnityEngine.XR.ARSubsystems.XRReferenceImage& referenceImage) [0x00000] in <00000000000000000000000000000000>:0 2025/02/26 18:08:29.483 23581 23601 Error Unity at UnityEngine.XR.ARSubsystems.MutableRuntimeReferenceImageLibrary.ScheduleAddImageWithValidationJob (Unity.Collections.NativeSlice1[T] imageBytes, UnityEngine.Vector2Int sizeInPixels, UnityEngine.TextureFormat format, UnityEngine.XR.ARSubsystems.XRReferenceImage referenceImage, Unity.Jobs.JobHandle inputDeps) [0x00000] in <00000000000000000000000000000000>:0
2025/02/26 18:08:29.483 23581 23601 Error Unity at UnityEngine.XR.ARFoundation.MutableRuntimeReferenceImageLibraryExtensions.ScheduleAddImageWithValidationJob (UnityEngine.XR.ARSubsystems.MutableRuntimeReferenceImageLibrary library, UnityEngine.Texture2D texture, System.String name, System.Nullable`1[T]

Hello, thanks for reaching out! I will have to ask around for you. What device are you testing it on, or are you testing it in the editor? In the meantime, please try seeing if this documentation helps you. It references how to set up new images at runtime for Unity’s ARFoundation Image Tracking, which the Niantic SDK is built on top of.

Thank you Josh!

I will look at the docs you sent me.

I am building for Android. In the editor the image tracking is disabled by the shared AR upm library and it just uses floor detection…I tried modifying it and using simulation for a tracked image but that breaks the co-location part so I am currently testing on a Pixel 6 phone.

Ana M.