Search Unity

How do you restart tracking to reposition an asset?

Discussion in 'Vuforia' started by monark, Sep 20, 2018.

  1. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    I'm trying to make an application that requires that AR be toggled on and off and when it's on the user should be able to reselect a position to spawn a set of objects.
    So far it's been a fun journey ;)

    I've managed to get something working well in the Editor but not when run on an iPad.

    Here's the flow
    1. Start the app with AR disabled.
    2. Allow the user to turn on AR using a button.
    3. Allow the user to select a spot to spawn some objects.
    4. Allow the user to turn off AR and do some other stuff.
    5. Go back to step 2. turn AR back on and then reposition the original set of objects to a new spot.

    All this is working but for the last step.
    I can get the first spawn to work and I can get a Plane Finder to show up and I can see that the script I have attached to the OnContentPlaced event is fired so I can turn off the plane finder, but when the objects are moved to the new position it just seems to randomly put them anywhere in space.

    I have a test app that doesn't try to turn the AR function on and off itself and that works perfectly.
    When that app is paused I call this:
    TrackerManager.Instance.GetTracker<ObjectTracker>().Stop();

    and when it unpauses this:
    TrackerManager.Instance.GetTracker<ObjectTracker>().Start();

    And that allows me to then update the position such that the objects appear where the user taps.

    But if I put in any code that does the pause unpause using a button to enable and disable the AR instead of hijacking OnApplicationPause it totally fails.

    Is there some trick I'm missing that lets you reinitialise the positioning code?

    I notice in the docs that it says
    Initializes the tracker of the given type Initializing a tracker must not be done when the CameraDevice is initialized or started. This function will return null if the CameraDevice is currently initialized.

    How do I make sure the CameraDevice is not initialised?
    At the point I start or stop the tracker manager the AR camera is disabled which appears to turn off all the Vuforia functionality and I had hoped would mean the CameraDevice is not started, but there seems to be no information on how to actually do what I want to do.

    Anyone done this or know how to achieve it?
     
  2. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    Ok I've found a reset button example in the Core samples, I'll see if that is the answer here. Seems to do mostly everything I want apart from disabling the AR completely which is were it all went wrong before.... Fingers crossed.
     
  3. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    Hmm so that doesn't work either. After re-enabling the AR camera the reset button no longer works the same way it does before you turn off AR.
    It resets the scene but you are stuck with the "Point device towards ground" message and it no longer detects the ground. Weirdly you can still place items but it just flickers between the "Point device towards ground" message and the ground plane graphic.

    That seems to indicate that either PerformHitTest or HandleAutomaticHitTest have stopped running, or aren't running correctly. How can we reset that?
     
    Last edited: Sep 21, 2018
  4. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    Ok I solved this in the end by putting all the AR camera and plane setup into a different scene and then loading the entire scene when needed and destroying it again when not. That appears to initialise correctly then when loaded in.
     
  5. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    ...unfortunately it was too much to ask that both ground plane and mid air positioner work this way. Mid air doesn't create a Mid Air Indicator when an AR scene with one is loaded into a standard scene. Lord only knows why.... face palm. Support seems to be non existent for AR.
     
  6. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    So it turns out it does create a mid air indicator but parents it to the first camera it finds not to the ARCamera.
    Also, you have to disable the Mid Air Positioner Behaviour script until Vuforia has started and then enable it via a registered callback in a script.
     
  7. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    420
    Hey.
    I'm currently facing a similar problem, but you wrote that it works for you fine when you use OnApplicationPause? My app is going into background when the user is going into an online store. I pause the device tracker then and unpause it when the app comes into foreground again. All my objects are misplaced then sadly, but I understood correctly that it is working for you?

    It would be great if we could see some debug infos about the device tracker and the ground plane how they are oriented and placed, 'cause this is rather a black box right now.
     
  8. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    It doesn't work from a situation like that as far as I can tell. In my situation I was only trying to get it to start from a none AR scene, once it starts I don't leave it again.
    I did find that if I took a screen shot and used a Prime31 plugin to display a message to the user I'd have the same issue you are facing but I just replaced that message with a Unity drawn UI element instead.
    So unfortunately I don't have a fix for you. I've not found a way to pause AR and come back to it in the state you left it.
     
    pahe likes this.
  9. veeoreye

    veeoreye

    Joined:
    Jul 12, 2018
    Posts:
    5
    Hi,

    Did changing scene work for you? I am facing a similar problem. I have a main scene, from there I can load 4 more scenes. Each of the new scenes are basically a copy of the Ground Plane sample scene (but with my own content). The only way to get to each of these scenes is going back to the main scene.

    When I load the first scene and content appears everything is fine. The problem is when I try to load my second scene, the content loads in the same position it did in the first scene (even if I am facing the opposite direction). For some reason the achor for the first scene isn't destroyed when moving between scenes.

    I tried calling:

    tracker = TrackerManager.Instance.InitTracker<PositionalDeviceTracker>();
    tracker.Reset();
    tracker.ResetAnchors();

    from the Start() of each new scene but it doesn't seem to change anything.

    I also tried TrackerManager.Instance.GetTracker<ObjectTracker>().Stop(); and TrackerManager.Instance.GetTracker<ObjectTracker>().Start();
    but it returns a null reference error.

    I have this script attached to the ARCamera. Where did you call the Stop() and Start() functions from?

    When you were changing scenes did you face a similar issue?
     
  10. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    I did initially but I solved it by loading the scene and then completely destroying it on exit.
    Because I didn't want to destroy any objects only the AR cameras and stages I had to keep them all in their own scene separate from any other objects.
    Vuforia itself seems to handle the start and stop in OnDestroy behaviours so completely destroying the AR camera scene worked best for me.
    The only place I used my own start and stop tracker was going into and out of a app pause state, so called from OnApllicationPause(bool pause)

    There doesn't appear to be any way currently to maintain any tracking if the entire app is paused and restarted. Maybe in the newer ARKit that will be possible I think, depending on how Vuforia adopt it.
     
  11. veeoreye

    veeoreye

    Joined:
    Jul 12, 2018
    Posts:
    5
    This is baffling.

    So in my case;
    My main scene has an ARCamera which I use to scan markers. The markers act as triggers to load these 4 other scenes.

    Each of the 4 other scenes have their own virtual content using Ground Plane.

    When I go from one of these 4 scenes to the main scene I destroy everything within the scene.
    I then load the main scene again using SceneManager.LoadScene

    Did you do anything else between scene transitions?
    No matter what, the virtual content in scenes 2, 3 and 4 always appears in the same place as the first scene. It's like the position is being cached somewhere.

    The only difference I can see between our projects is you are using one "main scene" using a normal camera and my main scene uses vuforia's AR camera, but tracking should be restarting each time so I don't understand why the position is always remembered.
     
  12. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    440
    I am not sure what are you trying to achieve, especially the "do some other stuff" part...
    but instead of turning on and off vuforia, maybe you can create 'root' that contains all the object you want to track as the child of your tracker object when you want it tracked and disconnect the root from tracker object(setparent null) when you dont want'to track the objects inside the 'root'
     
  13. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    Not sure either it's all a bit hit and miss I've found, the other difference is I never destroy my main scene only the VR one.
     
    veeoreye likes this.
  14. veeoreye

    veeoreye

    Joined:
    Jul 12, 2018
    Posts:
    5
    What I ended up doing was starting a new project and redownloading the vuforia core samples. There's a script called Plane Manager in the Ground plane sample scene that has a function called ResetTrackers(). It was exactly what I was looking for. It might also be useful for your case!
     
  15. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    I had already tried that route, it didn't work in my case. I only use it when the game is paused and unpaused whilst still in the VR scene
     
  16. jaredhank

    jaredhank

    Joined:
    Sep 18, 2018
    Posts:
    5
    @monark how did you get the objects to anchor? On my app I have the AR scene use ground plane detection, but every time i go to scale or rotate my object, it replaces it on the scene. I can't seem to find a way to disable that upon initial placement.
     
  17. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    I do the scaling after placement I'm afraid so I can't tell you.
     
  18. bebenzig

    bebenzig

    Joined:
    Jun 25, 2018
    Posts:
    9
    Hi veeoreye,
    can you tell me how to call the ResetTrackers() method? Seems to be what I'm searching for, but which class encapsulates that very method?