Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

ARFoundation: get tracked image name ?

Discussion in 'AR' started by shredingskin, Jul 29, 2019.

  1. shredingskin

    shredingskin

    Joined:
    Nov 7, 2012
    Posts:
    218
    Hello, I'm trying to change the trackedImagePrefab depending on what image I'm tracking.
    I've tried:
    if (m_TrackedImageManager.referenceLibrary.name.Equals())
    and
    TrackedImageManager..name.Equals
    But I can't seem to get it to work, any ideas ?
    THanks
     
  2. milkumich

    milkumich

    Joined:
    May 9, 2019
    Posts:
    2
    You can get an array (I think it's an array?) of image objects detected by the TrackedImageManager by using the OnTrackedImagesChanged function. Then just iterate through eventArgs.added (
    foreach (var trackedImage in eventArgs.added)
    ) and check if
    trackedImage.name.Equals("Your Image Name")
    .
     
  3. shredingskin

    shredingskin

    Joined:
    Nov 7, 2012
    Posts:
    218
    That's what I'm currently doing
    void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
    {
    foreach (var trackedImage in eventArgs.added)
    {
    // Give the initial image a reasonable default scale
    trackedImage.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
    Debug.Log(trackedImage.name);
    if (trackedImage.referenceImage.name == "Gnomo1")
    {
    m_TrackedImageManager.trackedImagePrefab = Prefab1;
    }
    else if (trackedImage.referenceImage.name == "Gnomo2")
    {
    m_TrackedImageManager.trackedImagePrefab = Prefab2;
    }
    //UpdateInfo(trackedImage);
    }
    }

    But it doesn't seem to work, it keeps using the default prefab set in the ImageTrackManager.
     
unityunity