OnMarkerFound event not getting called - Unity3D ARToolKit

空扰寡人 提交于 2019-12-12 02:56:21

问题


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.


EDIT - Answer

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.


回答1:


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.



来源:https://stackoverflow.com/questions/35248821/onmarkerfound-event-not-getting-called-unity3d-artoolkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!