Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug No Image names from Image Library

Discussion in 'AR' started by Dangers_Dad, Jan 15, 2023.

  1. Dangers_Dad

    Dangers_Dad

    Joined:
    Jan 8, 2023
    Posts:
    3
    Hi,

    I am trying to test out some features and I am struggling to find an answer online so I am asking for some suggestions or guidance if possible.

    I have followed a few tutorials to implement multi image tracking without using Vuforia.

    When trying to link the names of the images to the name of the Prefabs I come unstuck.

    It is looking like for each tracked image, the trackedimage.referenceImage.name is null.

    I have hardcoded the order of the models and it worked (some prefabs work, some don't, this is for another day) but when I try to link prefabs name and image name I am coming unstuck.

    Can anyone help or maybe suggest another way I can link different images to different prefabs?



    Code (CSharp):
    1. using System.Collections;
    2. using System.Linq;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.ARFoundation;
    6. using UnityEngine.XR.ARSubsystems;
    7.  
    8. [RequireComponent(typeof(ARTrackedImageManager))]
    9. public class ImageTracking : MonoBehaviour
    10. {
    11.     // Reference to AR Tracked Image Manager Component
    12.     private ARTrackedImageManager _trackedImageManager;
    13.  
    14.     // List of prefabs to instantiate
    15.     public GameObject[] ArPreFabs;
    16.  
    17.     // Keep dictionary Array of created prefabs
    18.     private readonly Dictionary<string, GameObject> _instantiatedPrefabs = new Dictionary<string, GameObject>();
    19.  
    20.     // Testing
    21.     //int num = 0;
    22.  
    23.     private void Awake()
    24.     {
    25.         // Cache a reference to tracked image manager
    26.         _trackedImageManager = GetComponent<ARTrackedImageManager>();
    27.  
    28.         Debug.Log("Tracked image Manager has this many images : " + _trackedImageManager.referenceLibrary.count);
    29.  
    30.     }
    31.  
    32.  
    33.     private void OnEnable()
    34.     {
    35.         _trackedImageManager.trackedImagesChanged += OnTrackedImageChanged;
    36.     }
    37.  
    38.     private void OnDisable()
    39.     {
    40.         _trackedImageManager.trackedImagesChanged -= OnTrackedImageChanged;
    41.     }
    42.  
    43.  
    44.     // Event Handler
    45.     private void OnTrackedImageChanged(ARTrackedImagesChangedEventArgs eventsArg)
    46.     {
    47.         // Loop through all new tracked images that have been detected
    48.         foreach (var trackedimage in eventsArg.added)
    49.         {
    50.             //Get the name of the reference image
    51.             var imageName = trackedimage.referenceImage.name;
    52.  
    53.  
    54.             // Now loop over the array of prefabs
    55.             foreach (var curPrefab in ArPreFabs)
    56.             {
    57.                 Instantiate(curPrefab, trackedimage.transform);
    58.  
    59.                 // Check whether this prefab matches the tracked image name, and hasnt already been created
    60.                 if (string.Compare(curPrefab.name, imageName, System.StringComparison.OrdinalIgnoreCase) == 0
    61.                     && !_instantiatedPrefabs.ContainsKey(imageName))
    62.                 {
    63.  
    64.                     // Instantiate the prefab, parenting it to the ARTrackedImage
    65.                     var newPrefab = Instantiate(curPrefab, trackedimage.transform);
    66.                     // And the created prefab to our array
    67.                     _instantiatedPrefabs[imageName] = newPrefab;
    68.  
    69.  
    70.                     Debug.Log("Instantiated prefab name: " + newPrefab.name);
    71.  
    72.  
    73.                 }
    74.             }
    75.         }
    76.  
    77.         // For all prefabs that have been created so far, set them to active or not depending
    78.         // on whether their corresponding image is currently being tracked
    79.         foreach (var trackedImage in eventsArg.removed)
    80.         {
    81.  
    82.             Debug.Log("image Removed: " + trackedImage.referenceImage.name);
    83.  
    84.             // Destroy Prefab
    85.             Destroy(_instantiatedPrefabs[trackedImage.referenceImage.name]);
    86.  
    87.             // Also remove the instance from our array
    88.             _instantiatedPrefabs.Remove(trackedImage.referenceImage.name);
    89.  
    90.             // Or simply set the prefab instance to inactive
    91.             //_instantiatedPrefabs[trackedImage.referenceImage.name].SetActive(false);
    92.  
    93.         }
    94.     }
    95. }
     
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    835
    @Dangers_Dad On which platform(s) did you observe a null referenceImage.name?
     
  3. Dangers_Dad

    Dangers_Dad

    Joined:
    Jan 8, 2023
    Posts:
    3
    @andyb-unity
    I was using AR Core for an Android build.

    I used Debug.Log to see what info I could find but no no detail came through although the image count was correct (4).
     
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    835
    And I'm assuming that you have filled out the name field for these Reference Images in your Reference Image Library?

    I don't have anything else to offer here. If you aren't able to resolve this issue please file a bug and post the bug number here so we can take a look at your case: https://unity3d.com/unity/qa/bug-reporting
     
  5. bisUWE

    bisUWE

    Joined:
    Jan 9, 2023
    Posts:
    1
    Hi I'm having a similar issue as the original poster.
    I've been following the Create a marker-based AR App tutorial here:
    https://learn.unity.com/tutorial/sp...984dedbc2a587fd7020e#6385cd51edbc2a0c6fdee241.

    I've successfully completed it using Unity Editor version 2021.3.1f1. I'm trying to apply what I have learned to a new project using Unity Editor 2022.3.7f1 (Build Target IOS), but keep on coming up against the following error:
    BuildFailedException: Reference image at Index 0 named 'Bis AR Marker' in library 'Assets/Markers/ReferenceImageLibrary.asset' is missing a texture.

    Despite having specified a Texture, removing and updating all the deprecated Components as directed? See attached screenshots.

    Is this a bug or am i missing something?
     

    Attached Files:

  6. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    202
    Are you sure the first screenshot shows the same asset the exception is complaining about? If so, can you try deleting the Library folder from your project and rebuilding?