Issue with ARTrackedImageManager with AR Foundation 6.0

So i recently upgraded my AR Foundation to 6.0 from 5.01 because I updated to URP and read 6.0 works well with URP.

The issue I’m having now is when i run in XR simulation I’m no longer able to track my image targets.

I updated my code to use trackablesChanges.AddListener and RemoveListener as well as changing to
ARTrackablesChangedEventArgs eventArgs

Here is the code where I’m using the ARTrackedImageManager

using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

public class ImageToPrefab : MonoBehaviour
{
    [SerializeField]
    private ARTrackedImageManager trackedImageManager;

    // Define public variables for the prefabs
    public GameObject prefab1;
    public GameObject prefab2;
    public GameObject prefab3;

    // Dictionary to hold the mappings from image names to prefab GameObjects
    public Dictionary<string, GameObject> imageToPrefab;

    // Dictionary to keep track of instantiated prefabs
    private Dictionary<string, GameObject> instantiatedPrefabs = new Dictionary<string, GameObject>();

    private void Awake()
    {
        // Initialize the dictionary based on your specific needs
        imageToPrefab = new Dictionary<string, GameObject>()
        {
            { "one", prefab1 },
            { "two", prefab2 },
            { "Tiki coaster", prefab3},
            // Add more mappings as needed
        };
    }
    void Start() {
    Debug.Log($"Library contains {trackedImageManager.referenceLibrary.count} images.");
}

    private void OnEnable() => trackedImageManager.trackablesChanged.AddListener(OnImageChanged);

    private void OnDisable() => trackedImageManager.trackablesChanged.RemoveListener(OnImageChanged);
   
    void OnImageChanged(ARTrackablesChangedEventArgs<ARTrackedImage> eventArgs)
    {
        foreach (var trackedImage in eventArgs.added)
        {
            InstantiatePrefabForImage(trackedImage);
        }

        foreach (var trackedImage in eventArgs.updated)
        {
            if (trackedImage.trackingState == TrackingState.Tracking)
            {
                InstantiatePrefabForImage(trackedImage);
            }
            else if (trackedImage.trackingState == TrackingState.None)
            {
                RemovePrefabForImage(trackedImage);
            }
        }

        foreach (var trackedImage in eventArgs.removed)
        {
            RemovePrefabForImage(trackedImage);
        }
    }

    private void InstantiatePrefabForImage(ARTrackedImage trackedImage)
    {
        string imageName = trackedImage.referenceImage.name;
        if (imageToPrefab.ContainsKey(imageName) && !instantiatedPrefabs.ContainsKey(imageName))
        {
            var prefab = imageToPrefab[imageName];
            var instance = Instantiate(prefab, trackedImage.transform.position, trackedImage.transform.rotation);
            instantiatedPrefabs[imageName] = instance;
            instance.transform.SetParent(trackedImage.transform);
        }
    }

    private void RemovePrefabForImage(ARTrackedImage trackedImage)
    {
        string imageName = trackedImage.referenceImage.name;
        if (instantiatedPrefabs.ContainsKey(imageName))
        {
            var instance = instantiatedPrefabs[imageName];
            Destroy(instance);
            instantiatedPrefabs.Remove(imageName);
        }
    }

    void Update()
    {
        if(Input.GetKeyUp(KeyCode.Space)){
            ListAllImages();
        }

    }

    void ListAllImages()
    {
        Debug.Log(
            $"There are {trackedImageManager.trackables.count} images being tracked.");

        foreach (var trackedImage in trackedImageManager.trackables)
        {
            Debug.Log($"Image: {trackedImage.referenceImage.name} is at " +
                      $"{trackedImage.transform.position}");
        }
    }
}

When i debug it i get through OnEnable but i never break into OnImageChanged. To note this was working perfectly fine before i updated to 6.0. Image Reference library is loading in all the images just nothing is getting tracked.

One thing im curious about that is new is with the attached image. The " trackables changed (ARTrackablesChangedEventArgs`1)" inside the AR Tracked Image Manager component list is new. Not sure if it has anything to do with my issue

Hello @tperez0711

The screenshot you provided for the ‘trackablesChanged’ event looks fine. That list purely represents the set of serialized event handlers that have been directly linked through the Unity Editor.

My first recommendation for you would be to try out the BasicImageTracking AR Foundation sample within the Editor using the ‘Billboard City’ simulation environment.

  1. Load the scene ‘BasicImageTracking’ into the Editor
  2. Add all of the images (through the UI button)
  3. Navigate the simulation environment by holding the right mouse button and using the mouse to look around, and the ‘WASD’ keys to move about
  4. Look up at the building sides and see the images get covered with an image info billboard.
  5. Modify the code behind this sample to see the trackables changed, and help diagnose your issue

I hope this helps resolve things for you.