Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2021 12:36
What would you like to do?
Reacting to new tracked images in AR Foundation (part 1)
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
   // Go through all tracked images that have been added
    // (-> new markers detected)
    foreach (var trackedImage in eventArgs.added
        // Get the name of the reference image to search for the corresponding prefab
        var imageName =;
        foreach (var curPrefab in ArPrefabs)
            if (string.Compare(curPrefab.nameimageNameStringComparison.Ordinal== 0 
                && !_instantiatedPrefabs.ContainsKey(imageName))
                // Found a corresponding prefab for the reference image, and it has not been 
// instantiated yet > new instance, with the ARTrackedImage as parent 
// (so it will automatically get updated when the marker changes in real life)
 var newPrefab = Instantiate(curPrefabtrackedImage.transform);
                // Store a reference to the created prefab
                _instantiatedPrefabs[imageName= newPrefab;
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment