Reputation: 1298
I am trying to get some custom behaviour implemented using ARToolKit SDK on Unity3D.
According to the documentation here, the ARCamera
uses the BroadcastMessage
system to call OnMarkerFound(ARMarker marker)
and OnMarkerLost(ARMarker marker)
to notify when a marker is found or lost.
However, I cannot get these functions to fire at all. I have gone through the entire source code, added debug watches, the works... But these two events are not firing.
My script looks like this:
using UnityEngine;
using System.Collections;
public class CustomTrack : MonoBehaviour {
void OnMarkerFound(ARMarker marker){
Debug.Log("MARKER FOUND! WHEEEE!");
}
void OnMarkerLost(ARMarker marker){
Debug.Log("MARKER LOST! WHEEEE!");
}
void OnMarkerTracked(ARMarker marker){
Debug.Log("MARKER TRACKED! WHEEEE!");
}
}
I have seen several other people on forums, etc. facing similar problems so it would be nice to finally have a solution to this issue.
Just to explain what I did to get this working, going by what @bleater said, I added the GameObject
to the ARTrackedObject
and then added my CustomScript
to the GameObject
. One mistake I was making was to attach the CustomScript
to the ARMarkerScene
. So, that worked. I hope this is useful to others as well.
Upvotes: 0
Views: 819
Reputation: 5499
The documentation is a bit out of date, as since ARToolKit for Unity v5.2 those events are generated by the ARTrackedObject component. The object that is to receive the events must be connected to the "Event receiver" on the ARTrackedObject, this is exposed in the Editor:
Since BroadcastMessage is used, the event receiver and any children will all receive the message, so if you need more than one GameObject to be called, put them into a group and make the parent object the event receiver.
Upvotes: 2