Trigger event on Target recognition

+1 vote
asked Aug 28, 2017 by akaiporo (160 points)
Hello everyone,

Is there any class or interface that would allow me to trigger an event when my application recognize a target ?

I want to launch an animation when the target is recognized (a slide transition, that would occur only once).

1 Answer

0 votes
answered Aug 28, 2017 by albert52 (31,850 points)
selected Aug 29, 2017 by akaiporo
 
Best answer

hi,

of course.(https://www.easyar.com/doc/EasyAR%20SDK/Getting%20Started/2.0/Setting-up-EasyAR-Unity-SDK.html)

public class EasyImageTargetBehaviour : ImageTargetBehaviour
{
    protected override void Awake()
    {
        base.Awake();
        TargetFound += OnTargetFound;
        TargetLost += OnTargetLost;
        TargetLoad += OnTargetLoad;
        TargetUnload += OnTargetUnload;
    }

    void OnTargetFound(TargetAbstractBehaviour behaviour)
    {
        Debug.Log("Found: " + Target.Id);
    }

    void OnTargetLost(TargetAbstractBehaviour behaviour)
    {
        Debug.Log("Lost: " + Target.Id);
    }

    void OnTargetLoad(ImageTargetBaseBehaviour behaviour, ImageTrackerBaseBehaviour tracker, bool status)
    {
        Debug.Log("Load target (" + status + "): " + Target.Id + " (" + Target.Name + ") " + " -> " + tracker);
    }

    void OnTargetUnload(ImageTargetBaseBehaviour behaviour, ImageTrackerBaseBehaviour tracker, bool status)
    {
        Debug.Log("Unload target (" + status + "): " + Target.Id + " (" + Target.Name + ") " + " -> " + tracker);
    }
}
commented Aug 29, 2017 by akaiporo (160 points)
Thank you ! It works just fine.
commented Aug 29, 2017 by akaiporo (160 points)
Well, sorry for bothering you again, but...
It works well, perfect, but my target randomly switch size. Sometimes it will be 1,1 it's nice, I can see my GameObject attached to it, but sometimes it will go 0,0 and nothing is actually displayed.
Size seems to change every time I get focus on my target. And even stranger, when I try to set it by script (Mytarget.Size = new Vector2(1, 1), and mytarget.transform.localScale = new Vector3(1, 1, 1), if I Debug.Log the size, it will displays (mytarget.Size = (1, 1), but in the Unity Inspector, it will actually be 0,0.

EDIT : I manage to still display my elements by not setting the target as a Parent. But I would still appreciate to understand how all of this work.
commented Sep 30, 2020 by mtmproject (100 points)
Hi, I am unable to find updated documentation related to tracking events for the api 4.x
commented May 11, 2022 by yoelrodguez (140 points)
Hello, is there an equivalent of this class for version 4.30 of easyar.
Thank you
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...