List
How to get gameObject of tracked trackable
Posted Date: 2019-11-23 6:54     Edited Date: 2019-11-26 5:50     Writer: inactive

Please provide your development details as below;

1. SDK Version: 4.1.3
2. Development Environment: Unity-Android
3. Tracker/Scanner: Tracker
4. License Type(Free / Pro-One Time Fee / Pro-Subscription / Enterprise): Free
5. Target Device(Optional): Android

I see this script on ImageTrackerSample.cs:

for (int i = 0; i < trackingResult.GetCount(); i++)
        {
            Trackable trackable = trackingResult.GetTrackable(i);
            imageTrackablesMap[trackable.GetName()].OnTrackSuccess(
                trackable.GetId(), trackable.GetName(), trackable.GetPose());
        }

I can get the Image Trackable Behaviour name using trackable.GetName() function, but how to get the gameObject instead?

Thank you

Posted Date: 2019-11-26 1:23     Edited Date: 2019-11-26 4:19     Writer: inactive

If you look at the Image Tracker Scene Manager, there is ImageTrackerSamples.cs. In that file, the Start function has the following code:

		ImageTrackableBehaviour[] imageTrackables = FindObjectsOfType();

        foreach (var trackable in imageTrackables)
		{
            string gameObject = trackable.gameObject.name;
            Debug.Log("GAME OBJECT NAME = " + gameObject);

            imageTrackablesMap.Add(trackable.TrackableName, trackable);
			Debug.Log("Trackable add: " + trackable.TrackableName);
		}

Find all ImageTrackableBehaviours and store them in an array.
After that, we put the ImageTrackableBehaviour's information into the dictionary as keys and values.
Here you can get a gameObject with a trackable attached.

Thank you.

 

Leo

Maxst Support Team

Posted Date: 2019-11-26 5:50     Edited Date: 2019-11-26 5:50     Writer: inactive

Great !! Thank you :D