Hi everyone,
I often get the question: “How to tell if the marker is detected in Unity3D?”
The easiest thing to find that out is to listen for the OnMarkerFound(ARMarker) and OnMarkerTracked(ARMarker) events. ARToolKit5 is sending the OnMarkerFound(ARMarker) event everytime a new marker is found. The OnMarkerTracked(ARMarker) is called every frame for as long as the marker is visible in the video stream.
Register for events
To register for such events it is easiest if you create a new script that implements the OnMarkerFound() and OnMarkerTracked() functions and to attach this script to a GameObject.
public class MarkerEvent : MonoBehaviour { void OnMarkerFound(ARMarker marker) { if (marker.Tag.Equals("Marker1")) { //Do something } } void OnMarkerTracked(ARMarker marker) { if (marker.Tag.Equals("Marker1")) { //Do something each frame } }
Now you need to go to your GameObject that contains the AR Tracked Object script. At the field Event Receiver click the circle on the right and choose your GameObject that contains the MarkerEvent-class.
This is it, now your script receives the marker events.
Bonus
Thanks for reading till the end As special bonus I’d like to tell you that there is another event function that you might be interested in. This is the onMarkerLost(ARMarker) event. You can use is to clean-up once the marker is not visible in the scene any longer.
Additional documentation
The event generation happens in these lines of code:
Let me know how if this works for you, thanks for reading and happy coding.
I want to control one object using two markers. For ex. When both the marker is visible than cube has blue color and when one marker is visible cube will have red color. How to use onmarkerfound, onmarkerlost eventrecievers in such a case?
Hi,
I would say you tag your 3D model that you would like to manipulate with a specific name. Let’s say ‘blueChange’. In onMarkerFound you look-up which marker was found and save it to a list. With this you know which markers are currently visible. In onMarkerLost you remove the lost marker from the list.
In onMarkerTracked you now scan the list if the two markers that should manipulate the ‘blueChange’ object are visible. If they are you look-up the ‘blueChange’ object and manipulate it.
Does that make sense?
Can you give me example simple project about Marker detection in Unity3D. i want to create one marker for multiple object. but, i didn’t know about your mean in this tutorial.
sorry my english
Are you trying to put multiple 3D objects onto the same marker? And hide/unhide them?