Log in or register to post comments

Change MarkerID of trackables at runtime

February 27, 2012 - 4:57am #1

Is it possible to change the MarkerId of the FrameMarker script at runtime?

I have a few hundred possible markers that could appear in a scene, so I'd prefer to manage them dynamically than having them all in the inspector view. Ideally I wanted to manage assigning detected markers to one of 5 possible slots to reduce any memory problems or messiness, but that now seems far too complex as I'm not that familiar with scripting (and not at all with C# / OOP principles).

I currently have a javascript class being called by the C# scripts in ontrackingfound and ontrackinglost in a TrackableEventHandler. In that class I can instantiate a framemarker prefab for every item in my list of markers/objects, name them with the ID, add a C# script that grabs the markerID from the framemarker on Awake(), but then I`m stuck as to where to apply the markerID. Ive tried in MarkerBehaviour, but I get lost as to whats being extended where etc.

I appreciate this will probably result in a hacky solution (especially going between JS and C# for no reason), but I have the JS already written so I'd like to just move ahead as quickly as possible for now.

EDIT *-----

Also if it will make the above make more sense I'll describe my original setup:

I have a scene manager that instantiates the 5 empty objects (5 rods in the real world) with modified MarkerBehaviours attached. This scene manager was supposed to receive any found/lost ID messages from QCAR, work out which rods were free/busy with animations , which markers are likely to appear together or previously appeared on rods etc., and assign the markers accordingly.

The MarkerBehaviours manage the appearing and disappearing animations, and whether objects should be destroyed or just hidden, as well as any prefabs spawned by the specific Marker (these unavoidably end up outside the hierarchy)

At the lowest level was a prefab script that stored the prefabs animations and preferences for the environment and FX (so cameras/FX can be added dynamically if approved by the scene manager).

This seemed like the easiest approach with an initial set of 100 items, which could easily increase to 500 (these occur in sets of 5, one ID for each rod). I came to Unity a few months ago from Max/MSP, so that might explain the focus on hierarchy.

Re: Change MarkerID of trackables at runtime

February 28, 2012 - 7:24pm #2

You can't change the marker id at runtime. However, you can instantiate frame markers at runtime using the following code:

MarkerTracker markerTracker = (MarkerTracker)TrackerManager.Instance.GetTracker(Tracker.Type.MARKER_TRACKER);

int markerId = 0;  // between 0 and 511

MarkerBehaviour mb = markerTracker.CreateMarker(markerId, "marker" + markerId, 100);
if (mb != null)
    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    cube.transform.parent = mb.transform;
    cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
    cube.transform.localPosition = new Vector3(0.0f, 0.25f, 0.0f);

Note this sample code places a cube as a child of the marker, you could place an instance of your prefab instead.

- Kim

Log in or register to post comments