How to get gameObject of tracked trackable
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
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
Great !! Thank you :D