[Unity] (manually) Starting /Stopping AR

Questions and discussion relating to the DAQRI-sponsored ARToolKit v6.0
Sejadis
Posts: 25
Joined: Thu Feb 09, 2017 8:36 am

[Unity] (manually) Starting /Stopping AR

Postby Sejadis » Fri Jul 14, 2017 1:29 am

Currently calling StopAR() or StartAR() is not enough to manually toggle AR at will. If you stop AR and try to start it again with StartAR() you get the "Cant start AR . Check if camera is connected popup" and the log shows "AR uninitialised" .
The initialisation stuff happens in OnEnable(). So to get it actually to (somewhat) work you have to either make sure that after every StopAR() call the ARController instance is disabled and enabled again before every StartAR() call or you have to disable and reenable it again before every StartAR() call.
At that point we at least have a camera image and no popup but its not tracking anything with the error: "arwQueryMarkerTransformation(): Couldn't locate trackable with UID 35"
As that goes into the pluginfunctions i haven't gone deeper here but the described scenario is also the reason why the AR crashes when the App/ Unity editor/ ... loses focus as the stop AR on pause and resume and unpause part is also just calling Stop-/StartAR.

Sejadis
Posts: 25
Joined: Thu Feb 09, 2017 8:36 am

Re: [Unity] (manually) Starting /Stopping AR

Postby Sejadis » Fri Aug 11, 2017 3:59 am

Any word on this?
Is it a bug in the current version? Am i doing something wrong? In case of a bug is there a workaround?

josef2172
Posts: 26
Joined: Wed Jun 14, 2017 3:54 pm

Re: [Unity] (manually) Starting /Stopping AR

Postby josef2172 » Sun Aug 13, 2017 5:04 pm

Hi,

You need to reinitialize ARToolKit after each StopAR() call and reload all the trackables manually. Just copy the same code snippet responsible of doing that from OnEnable() to your toggling function and it should work.

Regards,
Josef

Sejadis
Posts: 25
Joined: Thu Feb 09, 2017 8:36 am

Re: [Unity] (manually) Starting /Stopping AR

Postby Sejadis » Mon Aug 14, 2017 12:21 am

Hi,

currently i don't need my own toggle function and just want the "on Focus lost" / resume part to work.
So in addition to the StartAR() call in OnApplicationPause in ARCOntroller i also call OnEnable() which should reinitialise ARTK and also loops on all ARTrackables and loads all of them.
So basically i think I'm already doing what you suggested? Still getting the "arwQueryMarkerTransformation(): Couldn't locate trackable with UID 35" error

BigTsung
Posts: 15
Joined: Thu Jan 05, 2017 1:14 am

Re: [Unity] (manually) Starting /Stopping AR

Postby BigTsung » Tue Aug 22, 2017 11:14 pm

Hi,

I meet same error "Couldn't locate trackable with UID".
But I found the UID not reset to NO_ID(-1) in ARTrackable.cs. So I try to do Unload() for every ARTrackable object after I did StopAR().
I'm not sure whether that is correct, but it's working for me. :-)

Sejadis
Posts: 25
Joined: Thu Feb 09, 2017 8:36 am

Re: [Unity] (manually) Starting /Stopping AR

Postby Sejadis » Wed Sep 06, 2017 6:08 am

yeah unloading the trackables did work
ty

owae.ga
Posts: 11
Joined: Wed Sep 06, 2017 4:33 am

Re: [Unity] (manually) Starting /Stopping AR

Postby owae.ga » Thu Sep 21, 2017 5:08 am

Nice! Sejadis, Could you show the part of the code that you changed? Thanks!

Sejadis
Posts: 25
Joined: Thu Feb 09, 2017 8:36 am

Re: [Unity] (manually) Starting /Stopping AR

Postby Sejadis » Fri Sep 22, 2017 12:19 am

My complete OnApplicationPause method in ARController looks like this now:

Code: Select all

    void OnApplicationPause(bool paused)
    {

        Log(LogTag + "ARController.OnApplicationPause(" + paused + ")");
        if (paused)
        {
            if (_running)
            {
                _runOnUnpause = true;
                StopAR();

                ARTrackable[] trackables = FindObjectsOfType<ARTrackable>();
                foreach (ARTrackable t in trackables)
                {
                    foreach(Transform child in t.transform){
                        child.gameObject.SetActive(false);
                    }
                    t.Unload();
                }
            }
        }
        else
        {
            if (_runOnUnpause)
            {
                OnEnable();
                StartAR();

            }
            _runOnUnpause = false;
        }
    }

owae.ga
Posts: 11
Joined: Wed Sep 06, 2017 4:33 am

Re: [Unity] (manually) Starting /Stopping AR

Postby owae.ga » Fri Sep 22, 2017 1:42 am

Thanks! It works like a charme!!


Return to “ARToolKit v6.0”

Who is online

Users browsing this forum: No registered users and 2 guests