Log in or register to post comments

Access Trackable Name?

March 10, 2017 - 11:27am #1

How would I access the trackable name in my C# scripts in Unity?

I would like to trigger certain events based on when a certain trackable is discovered.

I see this line in the DefaultTrackableEventHandler.cs script, but I can't figure out how I would access it from one of my own scripts:

Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

How can I access that name from my own code?

I really appreciate any advice.

Access Trackable Name?

March 15, 2017 - 1:20am #2

Hi JK,

 

The quick hack I used was to modify the DefaultTrackableEventHandler.cs script and store the visibility of the markers in a global array which I called myFMFound.

Hope this helps. It works fine but if you find more elegant ways I'd love to know.

 

// Tom

 

public void OnTrackableStateChanged(

TrackableBehaviour.Status previousStatus,

TrackableBehaviour.Status newStatus)

{

if (newStatus == TrackableBehaviour.Status.DETECTED ||

newStatus == TrackableBehaviour.Status.TRACKED ||

newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

{

OnTrackingFound();

switch (mTrackableBehaviour.TrackableName){

case "mymarker0": myFMfound[0] = true; break;

case "mymarker1": myFMfound[1] = true; break;

case "mymarker2": myFMfound[2] = true; break;

case "mymarker3": myFMfound[3] = true; break;

case "FrameMarker4": myFMfound[4] = true; break;

case "FrameMarker5": myFMfound[5] = true; break;

case "FrameMarker6": myFMfound[6] = true; break;

case "FrameMarker15": myFMfound[15] = true; break;

case "FrameMarker20": myFMfound[20] = true; break;

}

}

else

{

OnTrackingLost();

switch (mTrackableBehaviour.TrackableName){

case "mymarker0": myFMfound[0] = false; break;

case "mymarker1": myFMfound[1] = false; break;

case "mymarker2": myFMfound[2] = false; break;

case "mymarker3": myFMfound[3] = false; break;

case "FrameMarker4": myFMfound[4] = false; break;

case "FrameMarker5": myFMfound[5] = false; break;

case "FrameMarker6": myFMfound[6] = false; break;

case "FrameMarker15": myFMfound[15] = false; break;

case "FrameMarker20": myFMfound[20] = false; break;

}

}

}

Log in or register to post comments