Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

ARFoundation: get tracked image name ?

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

  1. shredingskin

    shredingskin

    Joined:
    Nov 7, 2012
    Posts:
    145
    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:
    145
    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.