Search Unity

Vuforia initialization and deinitialization

Discussion in 'Vuforia' started by Din0m1te, Jan 29, 2018.

  1. Din0m1te

    Din0m1te

    Joined:
    Sep 9, 2015
    Posts:
    34
    I've been working with Vuforia a lot in the last 1,5 years and let me say, that it's a great piece of software I am glad exists. But I feel like Vuforia is making it incredibly hard for developers to decide THEMSELF when to use Vuforia and when not in an application.

    Something along the line:

    VuforiaRuntime.Instance.StartBeingAwesomeAndTakeWhatYouNeed()

    and

    VuforiaRuntime.Instace.StopWhateverYouAreDoingAndFreeUpTheResourcesYouAreUsingRightNowUntilIStartYouAgain()

    In Unity 2017.3 I've tried doing

    VuforiaRuntime.Instace.InitPlatform(...) but apparently the e.g. AndroidUnityPlayer etc. implementations of IUnityPlayer are not available anymore. So how does one Init and Deinit Vuforia at Runtime properly?
     
  2. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Hi @FejZa

    It is recommended to use the follow code to enable/disable Vuforia at runtime:

    VuforiaBehaviour.Instance.enabled = true/false;

    This behaviour is attached to your ARCamera and is accessible as a singleton.

    Let me know if you have any further questions.

    Thanks
     
  3. Din0m1te

    Din0m1te

    Joined:
    Sep 9, 2015
    Posts:
    34
    Hi @Vuforia-Strasza,

    thanks for your reply. From my experience this does not free up the device camera, that's why I do CameraDevice.Instance.Stop(); too.

    What is most important to me is deciding myself when to activate Vuforia. E.g. even with "Delayed Initiazation" set, Vuforia somehow gets initalized when I hit play. But that seems to be a known issue.

    Thanks again!
     
  4. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @FejZa Disabling the VuforiaBehaviour should be disabling the camera, tracker, datasets, etc. Are you consistently seeing this not be the case?
     
  5. Jeet_9811

    Jeet_9811

    Joined:
    May 6, 2014
    Posts:
    17
    @FejZa For disabling camera and vuforia you can do
    VuforiaRuntime.Instance.Deinit ();
    GetComponent<VuforiaBehaviour> ().enabled = false;
    GetComponent<DefaultInitializationErrorHandler> ().enabled = false;
    For initializing
    VuforiaRuntime.Instance.InitVuforia ();
    GetComponent<VuforiaBehaviour> ().enabled = true;
    GetComponent<DefaultInitializationErrorHandler> ().enabled = true;

    @Vuforia-Strasza
    Is it mandatory to do VuforiaBehaviour.Instance.enabled = true/false;
     
  6. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @Jeet_9811 I'd recommend enabling and disabling the VuforiaBehaviour instead of the VuforiaRuntime.
     
  7. SpaceScientist

    SpaceScientist

    Joined:
    Mar 7, 2018
    Posts:
    7
    FejZa, were you able to sort this out? I've been really struggling with Vuforia and how the camera keeps initializing in different scenes where it's not supposed to. I got it to stop working when I'm in first-image tracking mode but the second it switches to device-tracking (I'm using both), the main menu starts loading the Vuforia camera AGAIN.
     
  8. krreddy

    krreddy

    Joined:
    May 10, 2017
    Posts:
    3
    Hi @Vuforia-Strasza , I am using the vuforiaBehaviour.instance.enable = true/false whenever I want to disable vuforia for my application. The problem is whenever I enable vuforia, randomly the application crashes. It happens 4/10 times. I am using Vuforia for hololens. Can you let me know how I could solve this problems. Thanks in advance.
     
  9. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Could you share the crash log you are getting? Are you able to reproduce it within the sample project?
     
  10. krreddy

    krreddy

    Joined:
    May 10, 2017
    Posts:
    3
    @Vuforia-Strasza I managed to resolve the crash I was facing. It was because I was consuming the lower SDK of Vuforia. I have upgraded my Vuforia version to 7.0.50 and it fixes the crash. Thanks for the support.
     
    Vuforia-Strasza likes this.
  11. sharonj731

    sharonj731

    Joined:
    Jun 10, 2018
    Posts:
    8
    ************
    Hi @Vuforia-Strasza . I think I read where you say it's mandatory to use: VuforiaBehaviour.Instance.enabled = true/false;

    I've got multiple targets working in a single scene, and while everything works, I get problems loading the content on my device as each target has 2d video and 3d animations - the build up is crazy. Anyway, I'm attempting to split into multiple scenes. and I'm new to C#, and coding for that matter. I want to use Scene Manager.

    I've attempted putting the loadScene code in custom TrackableEventHandler.... and can't get it to work. Getting errors:
    Failed to set frame format
    Could not deactivate dataset.
    Could not destroy dataset.
    Could not deinitialize tracker.

    And the camera freezes when losing the target when testing on laptop. In the build, only the first scene loads, and so I see why.

    WHERE does the code go >>>>>>>>>>> VuforiaBehaviour.Instance.enabled = true/false;
    Am I going about it all wrong? I've uploaded my trackable event handler, which is where I'm attempting to do all this... I truly hope you can help. I appreciate any clarity you can bring to this.
     

    Attached Files:

  12. sharonj731

    sharonj731

    Joined:
    Jun 10, 2018
    Posts:
    8
    Where should this code* be placed in the Default Trackable Event Handler?
    Please tell me where, in the Default Trackable Event Handler will I place the code "VuforiaBehaviour.Instance.enabled = true/false;" ??
     
  13. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Where you place it depends on when you need to disable Vuforia. Default Trackable Event Handler is probably not the place you want to place it. When are you wanting to disable Vuforia? The answer to that question will determine where you disable it.
     
  14. sharonj731

    sharonj731

    Joined:
    Jun 10, 2018
    Posts:
    8
    Thanks for your response, Strasza! It turns out the errors about deinitializing went away when I removed some code that I was using to test. I went back to original code I was using and got back to an error free place with everything still working in the scene. Thank you.
     
    meedabit likes this.
  15. audry

    audry

    Joined:
    Feb 15, 2018
    Posts:
    4
    Hi. When i press play game , it takes around 25 seconds to initialize vuforia Ground plane detection. please help.
     
  16. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Could you share which version of Unity + Vuforia you are using as well as which device this is occurring on?
     
  17. audry

    audry

    Joined:
    Feb 15, 2018
    Posts:
    4
    I am using latest version of vuforia and unity in mac. It takes lot of time to initialize from splash screen to play screen in ipad as well as unity editor. i am using sample ground plane detection vuforia scene. Unity 2018.2.11f1 personal(64 bit)
     
  18. graum

    graum

    Joined:
    May 27, 2013
    Posts:
    9
    I am on Unity 2018.2.17f1 and Vuforia 7.5.26. I am only using ground plane detection. I'm trying to enable / disable Vuforia during AR scenes using

    VuforiaBehaviour.Instance.enabled = true/false;


    The first time I initialize and use Vuforia, everything works as expected, and I can detect ground planes, placing items on hit detection. However, when I disable and then enable, I no longer get any ground plane detection. This worked in previous versions (2018.1 Unity). Is there something I am missing? I am testing on iOS 12.0.1.

    Thanks for any help.
     
  19. meedabit

    meedabit

    Official Vuforia Employee Vuforia

    Joined:
    Dec 8, 2016
    Posts:
    266
    Hello,

    Between scenes, Vuforia is disabled and enabled again automatically. E.g. if you switch to a scene that does not use Vuforia, the camera, trackers etc. will be disabled automatically. If you switch back to a Vuforia scene, everything will be started again - this is the case in the VuforiaSamples app.

    That being said, we believe that the PositionalDeviceTracker and SmartTerrainTracker needs to be reset after disabling and enabling the VuforiaBehaviour, since the Ground Plane tracking will cease if the camera has been stopped.

    Thanks,
    Vuforia Engine Support
     
  20. rakeshn07

    rakeshn07

    Joined:
    Nov 28, 2018
    Posts:
    2
    Hi am working on unity with vuforia integration in ios. when am run the application i am getting this error
    CloudRecoBehaviour: TargetFinder initialization failed! and camara also not working . Its showing blank screen and crash my application.
    How can i solve this error in ios.

    Thanks for any help.
     

    Attached Files:

  21. Jeet_9811

    Jeet_9811

    Joined:
    May 6, 2014
    Posts:
    17
    You have to implement the OnInitialized method of the ICloudRecoEventHandler interface in your file and then assign the objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

    public void OnInitialized (Vuforia.TargetFinder targetFinder)
    {
    mImageTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
    }
    After then start the object tracking using objectTracker.Start()
     
  22. Ghus86

    Ghus86

    Joined:
    Oct 24, 2013
    Posts:
    15
    Hi

    I am having that message when integrating a unity project in a react native app
    It works fine if it is just unity

    But I dont understand why do you do that in the OnInitialized where do you use the mImageTracker ?