List
Trouble accessing methods OnTrackSuccess and OnTrackFail for ImageTrackable
Posted Date: 2019-06-25 15:59     Edited Date: 2021-01-31 11:52     Writer: inactive

1. SDK Version: 4.1.1
2. Development Environment: Unity-Android
3. Tracker/Scanner: Image
4. License Type: Free

Hi, I am trying to access the OnTrackSuccess and OnTrackFail methods in ImageTrackableBehaviour.cs so I can hide and show a graphic depending OnTrackingSuccess/Fail. Below is a simplified version of my script attached to the ImageTrackable prefab but it isn't working. There are no errors given either. Can you please assist?

 

using UnityEngine;

namespace maxstAR

{

    public class ImageTargetLanding : ImageTrackableBehaviour

    {

        public GameObject canvasGui;

        private bool tracking = false;

 

        public override void OnTrackSuccess(string id, string name, Matrix4x4 poseMatrix)

        {

            base.OnTrackSuccess(id, name, poseMatrix);

            canvasGui.SetActive(false);

            tracking = true;

        }

 

        public override void OnTrackFail()

        {

            if(tracking) {

                base.OnTrackFail();

                canvasGui.SetActive(true);

            }

        }

    }

}

Maybe my script has to access child component instead of ImageTrackableBehaviour directly to establish correct relationship. I will try tomorrow...

Posted Date: 2019-06-26 9:47     Edited Date: 2019-06-26 9:47     Writer: inactive

Hi maz.shah. 

I will tell you three things. 

1. Usually it shows the UI if the trace succeeds, and your code is to hide the UI when the trace is successful.

2. It is difficult to know exactly what the problem is with only the code you wrote down.

3. We do not officially help with code implementation.

 

Leo

Maxst Support Team

Posted Date: 2019-06-26 10:25     Edited Date: 2019-06-26 10:36     Writer: inactive

So in simple terms, I have the ImageTrackable prefab. I have just attached the ImageTargetLanding script to this prefeb. In my custom script, I just want to reference the ImageTrackableBehaviour component [that is already in the prefab gameobject] and access the OnTrackSuccess and OnTrackFail methods but it doesn't work...

For now I have added a public bool 'tracking' to ImageTrackableBehaviour. OnTrackSuccess I set this bool to true and OnTrackFail to false. Then in my own script I check ImageTrackableBehaviour.tracking and based on the result I show/hide graphic. But I do not like this solution. There must be a way to access methods ImageTrackableBehaviour.OnTrackSuccess / OnTrackFail directly in custom scripts...?

Posted Date: 2019-06-27 0:55     Edited Date: 2019-06-27 0:55     Writer: inactive

Sorry, but we can not help you implement your code. What we can help is answers to questions about Maxst SDK's normal / abnormal behavior and how to use the SDK.

 

Leo

Maxst Support Team

Posted Date: 2019-06-27 9:35     Edited Date: 2019-06-27 9:35     Writer: inactive

I think my question is SDK related. All I want to know is how I can access your ImageTrackableBehaviour.OnTrackSuccess method which is in your SDK?

Posted Date: 2019-06-28 2:01     Edited Date: 2019-06-28 2:01     Writer: inactive

If you look at the update function in imagetracker.cs, you can see the following sentence.

 

            for (int i = 0; i < trackingResult.GetCount(); i++)
            {
                Trackable trackable = trackingResult.GetTrackable(i);
                imageTrackablesMap[trackable.GetName()].OnTrackSuccess(
                    trackable.GetId(), trackable.GetName(), trackable.GetPose());
            }

 

In the trackable class, you can get the tracking result id, name, posematrix and you can call the OnTrackSuccess function by passing that information.

Thank you.

 

Leo

Maxst Support Team

Posted Date: 2021-01-31 11:52     Edited Date: 2021-01-31 11:52     Writer: inactive

maz.shah, did you ever figure this out? I'm having the same issue.

It seems like there is something in the inheretance path ImageTrackableBehaviour : AbstractImageTrackableBehaviour : AbstractTrackableBehaviour that prevents the prefab script from being able to affect UI components. I can't figure out what it is though.

If I change OnTrackFail() to:
...
public overide void OnTrackFail()
{
    gameObject.transformGetChild{0}.gameObject.setActive(false)
}

It will work fine on any 3D object. However, if I add a Canvas, or any kind of UI object, it does nothing