Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Do not run Vufory when the application starts

Discussion in 'Vuforia' started by Ark_Tarusov, Oct 2, 2017.

  1. Ark_Tarusov

    Ark_Tarusov

    Joined:
    Jun 24, 2016
    Posts:
    19
    The problem is that Vuforia automatically turns on when the application is launched. Even when it is not necessary!
    How to disable and enable it only in the desired scene?
    It replaces the camera settings, creates BackgroundPlane and TextureBufferCamera, which spoil the scene!
    And this is not necessary!
    How to get rid of this error?

    Unity 2017.2.0f1 (64-bit)

    Thank you in advance!
     
    Last edited: Oct 2, 2017
  2. M_PLY

    M_PLY

    Joined:
    Nov 17, 2014
    Posts:
    11
    I have the same problem.
    In every scene with a camera, a second camera is created with TextureBufferCamera and BackgroundPlane. Why would anyone assume that in a Unity-Project every single scene would want to use an AR camera?

    Since deleting this camera in every single scene I don't need it is a rather inelegant solution, could someone tell me which script is creating this camera and where I can turn it off? In my quick search I couldn't find the script controlling whether an AR camera should be loaded into the scene or not. In the Vuforia samples the scenes that don't load an AR camera is because they don't have ANY camera in the scene.

    We just need the info where we can turn off this automatic loading of a second AR camera into the scenes we don't want to.

    Thank you in advance.
     
  3. M_PLY

    M_PLY

    Joined:
    Nov 17, 2014
    Posts:
    11
    Apart from creating a new GameObject called TextureBufferCamera, the main camera of the scene also gets added 3 Components.
    1. VideoBackgroundBehaviour
    2. VuforiaBehaviour
    3. DefaultInitializationErrorHandlerInternal
    I can't delete the last component because it is protected. Looking for a way to stop AR working on a scene I looked into the documentation.
    To my surprise there is no documentation with the "Vuforia" namespace.
    Reading through UnityEngine.XR I came across this:
    Code (CSharp):
    1. XRSettings.enabled = false;
    But it does nothing. I tried to set the ARRenderMode.StandardBackground without success.
    VuforiaBehaviour.Stop() or something like that doesn't work either.

    I would really appreciate any input here.

    Best Regards,

    Roland
     
    Last edited: Oct 2, 2017
    Ark_Tarusov likes this.
  4. vinnie-vivace

    vinnie-vivace

    Joined:
    Jan 12, 2010
    Posts:
    28
  5. Ark_Tarusov

    Ark_Tarusov

    Joined:
    Jun 24, 2016
    Posts:
    19
  6. Ark_Tarusov

    Ark_Tarusov

    Joined:
    Jun 24, 2016
    Posts:
    19
    I tried to disable all the elements with the code, it did not help. Let's try to clone and delete the camera.
     
  7. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    So how I get around this is by setting Vuforia to a delayed initialization in the Vuforia settings, located in the resources folder, and initializing and de-initializing it manually with code at the start and end of the scenes I want to use Vuforia in. Make sure you de- initialize it though because if initialized as soon as Vuforia notices a main camera without it's properties it will fix it. I'm not at my PC so I can't put any examples here but if you need one let me know and I will post some examples of how to do it. A lot of the documentation on how to do this is on Vuforia's site I haven't looked over Unity's manual in a while not sure if they added Vuforia calls in there.
     
    M_PLY likes this.
  8. Augmenteer

    Augmenteer

    Joined:
    Aug 30, 2015
    Posts:
    43
    I think we need better documentation for this question. Hope this helps...

    When Vuforia AR Support is activated in XR Settings, it is enabled for every scene in your project. In this way Vuforia support behaves like an XR Support Device - it's automatically configured and available in a scene.

    To disable Vuforia in a scene, you need to disable the Vuforia Behaviour.

    To disable on the Main Camera, add a VuforiaBehaviour script from Component > Scripts > Vuforia in the menu.
    Then disable (uncheck) that script component.

    To disable on an ARCamera, simply disable on the ARCamera GO.
     
  9. Ark_Tarusov

    Ark_Tarusov

    Joined:
    Jun 24, 2016
    Posts:
    19
    Good afternoon, thanks for the answer!
    Yes, the documentation after the introduction of "Vuforia" in "Unity" has gaps.
     
  10. Ark_Tarusov

    Ark_Tarusov

    Joined:
    Jun 24, 2016
    Posts:
    19
    Good afternoon, thank you for your advice!
    I probably did not look very well at the documentation, but neither on the Unity website nor on the Vuforia website did I find information on this issue.
    Can you provide me with a link to this documentation?
    And it will be very cool if you demonstrate examples of solving this problem by you, for the community.
    .
     
  11. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    Yeah not a problem I will show how I do it in my next post
     
    M_PLY likes this.
  12. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    Ok so how I get around the always on "feature" is by only Initializing it when I need it.

    My application might not be the exact as yours so the way to do this and the order of these steps might vary.

    My application is an online application where there is one "teacher" player and several "student" players. The "teachers" have an AR camera powered by Vuforia while the students are observing the teacher in a virtual classroom. My application can be launched as either a student or a teacher and there are UI to select rooms to join all powered by Unity's Unet. So in my case Vuforia always being on was an issue.

    The first thing to do is to delay the Initialization of Vuforia look at image attached.


    Then when you want to turn on the AR camera you do something like this.

    Code (CSharp):
    1.     private void SearchforGames()
    2.     {
    3.         if (playerPrefabIndex == 0)
    4.         {
    5.             TeacherVersion = true;
    6.             VuforiaRuntime.Instance.InitVuforia(); // This is how you turn vuforia on!
    7.             matchMaker.CreateMatch(GameName, GameSize, true, "", "", "", 0, 0, OnMatchCreate);
    8.         }
    9.         else
    10.         {
    11.             matchName = GameName;
    12.             matchMaker.JoinMatch((UnityEngine.Networking.Types.NetworkID)GameID, "", "", "", 0, 0, OnMatchJoined);
    13.         }
    14.     }
    So since my application in a multiplayer application my spawning is handled by the match maker nothing special there.

    I also have a script attached to my teacher prefab that will turn on the correct scripts. If it is only being spawned as a local player there is no need in my case to have these running if a student launches into the game. Here is the script that will turn things on the Vuforia behavior attached to the teacher camera I also attached what the prefab looks like before it spawns.


    Code (CSharp):
    1.     void Start ()
    2.     {
    3.         if (isLocalPlayer)
    4.         {
    5.             manager = GameObject.FindObjectOfType<NetworkManagerCustom2>();
    6.             manager.DoneLoading();
    7.  
    8.             //These are some Vuforia scripts to turn on!
    9.             GetComponent<VuforiaBehaviour>().enabled = true;
    10.             GetComponent<DefaultInitializationErrorHandler>().enabled = true;
    11.         }
    12.         else
    13.         {
    14.             GetComponent<Camera>().enabled = false;
    15.             GetComponent<AudioListener>().enabled = false;
    16.         }
    And before you leave the scene if going back to the lobby or another no AR scene make sure you call.

    Code (CSharp):
    1. VuforiaRuntime.Instance.Deinit ()
    Like I said this is my case and how I handled it with multiplayer when not all players are Vuforia players. The main things to take away from this is: InitVuforia before you spawn and then turn on the vuforia behavior after you spawn.

    Turning on and off vuforia in one scene is a little easier as you don't have to worry about InitVuforia() and Deinit(). just do something like this.


    Code (CSharp):
    1. //Turn off Vuforia
    2. VuforiaBehaviour.Instance.enabled = false;
    3. ImageTracker.enabled = false;
    Code (CSharp):
    1. //Turn on Vuforia
    2. VuforiaBehaviour.Instance.enabled = true;
    3. ImageTracker.enabled = true;
     
    Last edited: Oct 5, 2017
  13. Ark_Tarusov

    Ark_Tarusov

    Joined:
    Jun 24, 2016
    Posts:
    19
    Many thanks for the detailed answer!
    I am very grateful.
     
    Vuforia-Strasza and whitebozo like this.
  14. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    So something I forgot to mention is if you use
    Code (CSharp):
    1. VuforiaRuntime.Instance.InitVuforia();
    You want to make sure it fully initializes before you try and turn on the vuforia behavior. In my case given above, Unet takes time to spawn a player so it is plenty of time. In other cases where you want to initialize Vuforia and immediately start the app you need to make sure you check it is initialized by calling HasInitialized in an 'if' statement in the Update function instead of the Start function.

    Code (CSharp):
    1.  
    2. //VuforiaOn is just and example of a bool to flag that this has been done no need to do this more than once in the update function
    3. if(!VuforiaOn && VuforiaRuntime.Instance.HasInitialized)
    4. {
    5.             GetComponent<VuforiaBehaviour>().enabled = true;
    6.             GetComponent<DefaultInitializationErrorHandler>().enabled = true;
    7.             VuforiaOn = true;
    8. }
    Here is a link to some references for the future.
    https://library.vuforia.com/content...nce/unity/classVuforia_1_1VuforiaRuntime.html

    It does take some practice to make some of these things work the way you want. I'm no expert at this stuff just been using Vuforia for a while and I had to learn a few new things with the new Unity migration and there isn't much documentation on using the version with wearables. There is also no sample project for wearables either... On Vuforia's site it just says coming soon to the asset store... At this point I just wish they had a link to the old samples. I'm mid way through porting this application I described above to hololens and it is not going smoothly lol.
     
    M_PLY and Vuforia-Strasza like this.
  15. pdyxs

    pdyxs

    Joined:
    Sep 7, 2012
    Posts:
    6
    @joshua-white I'm finding that if you check 'delayed initialisation', even though Vuforia doesn't actually run the webcam, it still initialises and attaches a background plane object to the Main Camera - have you found this as well? The only way I've seen to properly stop it from affecting the camera is to attach a disabled VuforiaBehaviour to it.
     
  16. vinnie-vivace

    vinnie-vivace

    Joined:
    Jan 12, 2010
    Posts:
    28
    @pdyxs I saw the same result as you, delayed initialisation did not work as outlined above.
     
  17. whitebozo

    whitebozo

    Joined:
    Oct 27, 2014
    Posts:
    24
    Yes I mentioned above that I had a prefab that I spawned in. It already has the Vuforia behavior and it is turned off in the inspector I only turn it on when I want to. If you are not going to spawn in a camera and you do not want unity to automatically place the components on the object. Place them on in the scene and turn them off in the inspector. You can then turn them on when you need it. If you want a scene that is fully never AR you should be able to spawn in a camera through script in a start function. The spawned camera does not need the components and as far as I remember Unity won't place them on the spawned camera as I think it only does that at the very start of the scene if the object doesn't have it, but if you start a scene without a camera and spawn one in it should avoid having the components you don't need. But in my opinion that is a little overkill and is best to just place the components on the camera and disable them. It doesn't hurt anything especially if Vuforia is not initialized.
     
    Vuforia-Strasza likes this.
  18. TomsDC

    TomsDC

    Joined:
    Apr 25, 2017
    Posts:
    3
    I'm afraid that doesn't work in my scenario. I have a multi-scene + multi-camera setup. My specific problem is:

    I have a scene with two cameras in it. One of those cameras is a Vuforia ARCamera. The other is not. One renders the AR view whilst the other is there to render a non-ar equivalent view. Both cameras are needed in the scene. The ARCamera must start with its GameObject de-activated. The non-AR camera needs to start activated. I do what you say for the non-AR camera and give it a VuforiaBehaviour and turn this component off, and everything is fine. However, when I activate the ARCamera's GameObject, which also has a VuforiaBehaviour attached to it, I get an error warning saying "It's not possible to have two ARCameras at the same time".

    This is a problem for me, as when I activate that ARCamera, I can't see the AR view. My app needs to be able to toggle between a non-AR view and an AR view. How is this achievable in Vuforia's current state? This really is an issue guys. Whilst I understand what you are trying to achieve by allowing access to Vuforia in every scene, I don't think that this is the way to go. Implementing a new feature/methodology like this all of a sudden and changing the normal workflow of Vuforia is a bit strange to me. Can you please assist me with my issue and offer a fix?
     
  19. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @TomsDC You can add a camera to the scene that is not an ARCamera. If you right click in the Hierarchy and add a Camera object, you can use this camera without having any Vuforia Components on it. Make sure it does not have the "MainCamera" tag as this is what Vuforia will add the ARCamera components to.

    This should allow you to have the ARCamera setup and initially disabled while having the "MainCamera" tag and then your second camera without any Vuforia Components that can be used for non-AR needs.

    Could you give something like this a try and let me know if it resolves the issue you are facing?

    Thanks!
     
  20. lrb

    lrb

    Joined:
    Jun 21, 2014
    Posts:
    18
    I agree with @TomsDC, this situations really sucks! I've been a long time to realize that the Default behavior is "activate each Camera in every scene", so why there is an "AR Camera" on GameObject/Vuforia if every normal Camera was immediately affected? Well, after that I found this topic and the solution to attach a disabled Vuforia Behaviour component that resolves for a moment (still making no sense btw).

    Now I have another problem, when I load a scene that finally uses Vuforia capabilities and after that I go back to another scene (already with a disabled Vuforia Behaviour), I have the Vuforia scene loading every time again, automatically. I tried to disable the component by " VuforiaBehaviour.Instance.enabled = false;", which works directly on Unity but has no effect on smartphone.

    Thanks guys for the hard work but this really really sucks and till now makes any sense.
     
    Last edited: Nov 11, 2017
    kmsuzanna likes this.
  21. TigerBooks

    TigerBooks

    Joined:
    Jul 31, 2015
    Posts:
    9
    @Vuforia-Strasza I basically have the same setup as @TomsDC This is my Setup

    ARCamera (has MainCamera Tag, it's GameObject is disabled, VuforiaBehaviour is disabled)
    Non-AR Camera (has no Tags, it's GameObject is disabled, no VuforiaBehaviour)
    I also activated delayed initilization.

    When I start my scene the vuforia components get added to my Non-AR Camera. I don't understand why these components are needed if we don't want to activate AR at the start. I think the best solution would be that you don't add these components. Instead through a warning and let us add these components if and when we need it.

    EDIT:
    If I start the scene with the ARCamera GameObject active then no components get added. But I then I have this Camera active, which I clearly don't wanted.
     
    Andresanvidria likes this.
  22. atorisa

    atorisa

    Joined:
    Dec 1, 2013
    Posts:
    85
    When will the situation be normalized from the box?
     
  23. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @lrb I need to do some investigation and I'll try to get back to you with an answer on this. Sorry I don't have a solution for you right now.

    @TigerBooks My best recommendation for your situation would be to add a script that runs at startup to disable and enable the correct behaviors and cameras.

    @atorisa I've spoken with @Augmenteer about these concerns and hopefully he can give some better insight into how and when we might resolve this concern.
     
  24. Andresanvidria

    Andresanvidria

    Joined:
    Mar 13, 2017
    Posts:
    1
    I have the same problem, I have 5 scenes an only one with AR camera but when I test my app, al the scenes open AR camera and I don´t need it. Do you find any solution? best regards.
     
  25. jamesmunro

    jamesmunro

    Joined:
    May 23, 2016
    Posts:
    3
    @Vuforia-Strasza Why are you forcibly adding components to a camera tagged as "MainCamera"? Wouldn't a simple fix be to use a different tag, e.g. "ARCamera", and not override the default behaviour of fundamental components of Unity like the concept of what is the main camera? Or just leave it up to the user to decide which components to add to their game objects so that we can choose whether a camera is AR enabled or not?
     
  26. jamesmunro

    jamesmunro

    Joined:
    May 23, 2016
    Posts:
    3
    As a fairly dirty hack you can add a disabled VuforiaBehaviour script to any camera to stop Vuforia from forcing additional scripts to be added where you do not want them. This will at least remove the errors on each scene load if you have set delayed initialisation.

    This appears to work due to the way in which all of the tracking scripts are added in Vuforia. It looks like it's performing a check to see whether VuforiaBehaviour exists on any of the cameras in a scene to decide whether or not to add it and the other ones it requires.

    You'll still need to use the above solutions for delayed initialisation and trigger Vuforia to enable/disable on scenes that actually require it.
     
  27. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @Andresanvidria This thread goes over a solution to that problem.

    @jamesmunro We're aware that this is not an ideal implementation. @Augmenteer might have more information on when this will be improved.
     
  28. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    651
    Please Please Please fix this.
    Is this something that we can expect fixed in the next few months?

    I have permission issues with "splitApplicationBinary" and Android OBB loader. If a user installs the Android app but was unable to download the OBB, it causes Vuforia to ask for permissions.

    We've got some restrictions on showing permissions at startup for Android. I've tried adding a disabled Vuforia Behaviour, even removing all cameras in the scene. Vuforia still asks for camera permission on startup.

    Really need this fixed ASAP
     
    Last edited: Nov 19, 2017
    andersemil likes this.
  29. yvrez

    yvrez

    Joined:
    Mar 7, 2010
    Posts:
    19
    That's a mess ! I have 20+ scenes with different settings & camera setup how could you guys leave something like this to be released i don't get it.

    Since you have a Vuforia menu that allow to add a ARCamera instance at any time in the scene you should only enable AR when this component is active in a specific scene i think.
     
  30. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    704
    please fix this, as this error affects over 4 million unity developers now that Vuforia has been force-integrated into Unity
     
  31. prasetion

    prasetion

    Joined:
    Apr 3, 2014
    Posts:
    14
    agree to fix this asap and hopefully Vuforia or unity has documentation about using all vuforia feature. Because right now it is so hard to make a custom behaviour in newest vuforia.
     
    theolagendijk likes this.
  32. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    37
    Adding my voice to those affected by this. Why oh why was it implemented this way??? I only want vuforia in active in one live scene (and maybe a few 'test' scenes) all the others are the other gameplay modes (i.e. like how - Pokemon go has a map and then you go into the AR from there)

    This was so bad I had to stop using the updated version of Unity and roll back to the previous version because I couldn't get a handle on all the S*** the 'integrated' version was causing. Integration was supposed to make Vuforia more streamlined - not less streamlined!!!

    Having to add a script to DISABLE something is now how unity is supposed to work - nor is removing it to reenable it. I basically have to add this to all my cameras by default and then remember to remove it if I need to test something for some reason.

    Did you guys not do any quality assurance tests from people who were actually using the software - or was it all internal people!? Absolutely horrible.
     
  33. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    Unfortunately, this makes the Vuforia 6.5 unusable.
    I will not add workarounds to all scenes of my project simply because the AR plugin is messing with the MainCameras.
    I hope you guys release a new version ASAP because this is really sad Vuforia. I feel disrespected as a Vuforia customer.
     
  34. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    651
    I really want to know when this might be fixed. A month?, 3 months? 2 years? Unity 2030.2?

    This should be top priority for the next update.
     
  35. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    704
    yeah, disappointed that with unity editor integration, vuforia roadmap is still very uncertain
     
    theolagendijk likes this.
  36. EdgarSantos

    EdgarSantos

    Joined:
    Nov 11, 2013
    Posts:
    4
    I'd like to add one thing.

    I am currently using Delayed Initialization and calling "VuforiaRuntime.Instance.InitVuforia();" manually after a scene with the image targets and actual logic is loaded. (and yes, I'm waiting for the HasInitialized flag to be "true")

    When that scene is unloaded, I'm calling "VuforiaRuntime.Instance.DeInit()".

    If I re-load the previous scene and call "VuforiaRuntime.Instance.InitVuforia();" again, the "VuforiaRuntime.Instance.HasInitialized" flag is immediately set to true, and when I try to enable the VuforiaBehavior script I get the error "Could not start tracker.".

    It is currently impossible to restart a "level" with AR tracking because of this as it seems the Vuforia objects' lifecycle is not even managed properly. First time InitVuforia is called it works fine. After "DeInit" and "Init"again, it just doesn't work.

    Am I missing something here?
     
    sinjimonkey likes this.
  37. EdgarSantos

    EdgarSantos

    Joined:
    Nov 11, 2013
    Posts:
    4
    Just to add some more context to the previous post:

    The reason I need Init/DeInit to work is because ImageTargets somehow "register" in the VuforiaBehavior and never "unregister". This means that if ImageTargets need to be deleted (they're part of a level, for example), VuforiaBehavior will forever crash because it tries to access an ImageTarget that doesn't exist in memory anymore.

    As I said before, the object's lifecyle is a mess and we can't even work around it because code is closed for both VuforiaBehavior and ImageTarget.

    I also tried removing and adding a VuforiaBehavior everytime a new scene was loaded. This also doesn't work, same issue with the "ImageTarget not in memory anymore" exception in VuforiaBehavior.

    As of right now, Vuforia is unusable in a real-world app that needs to load and swap between different levels with different image targets.

    If i'm missing something here, please do tell, I'll gladly share some code (I did make a lot of progress).

    I was thinking about opening a new thread with this, but this thread touches Vuforia objects' lifecycle which seems to cause all of our problems.
     
  38. skdev3

    skdev3

    Joined:
    Jul 15, 2015
    Posts:
    48
    How to use Delayed initialization option?
     
  39. vinod198

    vinod198

    Joined:
    Jan 12, 2014
    Posts:
    4
    TLDR: Call VuforiaBehaviour.Instance.enabled = false; before calling VuforiaRuntime.Instance.Deinit();

    I had the same problem and somehow I fixed it with something I think that is not-hacky.

    My setup was a menu scene and a game scene where I wanted vuforia to be enabled only in game scene.

    From above comments I came up with this with no errors on console.

    First I enabled Delayed Initialization in Vuforia configuration.

    Then in my menu scene.
    Code (CSharp):
    1. void Start () {
    2.     VuforiaRuntime.Instance.Deinit();
    3. }

    And to start the game.
    Code (CSharp):
    1. StartCoroutine(StartVuforiaAndPlay());
    2.  
    3. IEnumerator StartVuforiaAndPlay()
    4. {
    5.     VuforiaRuntime.Instance.InitVuforia();
    6.     while (!VuforiaRuntime.Instance.HasInitialized)
    7.     {
    8.         yield return null;
    9.     }
    10.     SceneManager.LoadSceneAsync("Game");
    11. }

    And in the game, to exit the scene.
    Code (CSharp):
    1.  
    2. void Update () {
    3.     if (Input.GetKeyDown(KeyCode.Escape))
    4.     {
    5.         VuforiaBehaviour.Instance.enabled = false;
    6.         SceneManager.LoadScene("Menu");
    7.     }
    8. }
    9.  
    This will make sure everything is disabled and before the Deinit() call in the Menu scene.
    The only error I get is the one which Vuforia is not initialized because of Delayed Initialization is enabled - which is not an error by the way.
     
    Railon23 and theolagendijk like this.
  40. vinod198

    vinod198

    Joined:
    Jan 12, 2014
    Posts:
    4
    Improving on the above, I made a singleton to manage these.
    This will listen to scene changes and disables Vuforia accordingly.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using System.Linq;
    6. using Vuforia;
    7.  
    8. public class VuforiaDisabler : MonoBehaviour {
    9.  
    10.     public static VuforiaDisabler instance;
    11.  
    12.     [SerializeField]
    13.     private string[] sceneNamesWithAR;
    14.  
    15.     // Use this for initialization
    16.     void Start () {
    17.         if (instance == null)
    18.         {
    19.             instance = this;
    20.         }else
    21.         {
    22.             Destroy(this.gameObject);
    23.             return;
    24.         }
    25.  
    26.         DontDestroyOnLoad(this.gameObject);
    27.         SceneManager.sceneLoaded += sceneChanged;
    28.     }
    29.  
    30.     private void sceneChanged(Scene scene, LoadSceneMode m)
    31.     {
    32.         //Debug.Log("Scene changed to " + scene.name);
    33.         if (!sceneNamesWithAR.Contains(scene.name))
    34.         {
    35.             VuforiaBehaviour.Instance.enabled = false;
    36.             VuforiaRuntime.Instance.Deinit();
    37.         }
    38.  
    39.     }
    40.  
    41.     void OnDestroy()
    42.     {
    43.         SceneManager.sceneLoaded -= sceneChanged;
    44.     }
    45.    
    46.    
    47. }
    48.  
     
  41. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    55
    Hi vinod198 I am trying to replicate your approach, but Vuforia adds a VuforiaBehaviour the Menu scene camera (nonAR) and throws a "Vuforia cannot be started message".
    Do I have to add a disable Vuforiabehaviour to the Camera of the Menu Scene?
    I alos have to scene on Menu scene non AR and one Game scene AR.....

    Thanks


     
  42. vinod198

    vinod198

    Joined:
    Jan 12, 2014
    Posts:
    4
    You need to enable delayed initialisation first.
    Then use the above singleton.

    To start the ar scene, use the code in my first post.
     
  43. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    55
    Ok let's be more explicit. My menu scene is non AR. I have one simple camera, a canvas UI with buttons and a box.
    I enabled of course delayed initialization and added your singleton. As soon as i run the editor Vuforia Attaches a VuforiaBehaviour script... And i get a message Vuforia can not be started before its initialised.
    The singleton is never called...

    The only way to avoid the message is either attaching a Vuforiabehaviour script yourself and disabling it. Or disable the script on Start using VuforiaBehaviour.Instance.enabled = false;

    When you disable the script on the start function Vuforia attaches a VuforiaBehaviour script and Video Backgroundbehaviour and Default Initialization handler.
    When you attach a disabled VuforiaBehaviour yourself, you done get any additional scripts added to you camera.

    The fact is that even with Delayed Initializtion on you get the Vuforia Scripts unless you add them disabled yourself.
     

    Attached Files:

  44. vinod198

    vinod198

    Joined:
    Jan 12, 2014
    Posts:
    4
    I think that is not actually an error message. It just says Vuforia cannot be started before it is initialised.

    That is more like an information.

    If we call init, then Vuforia will continue to work on other scenes. The game will run fine without any problems. Atleast that's what I am getting.
     
    Christop likes this.
  45. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    Is this fixed in Unity 2017.3?
     
    Last edited: Dec 19, 2017
  46. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    This is currently being addressed for a future build, but the functionality in 2017.3 currently remains the same. I'll provide more updates as they become available.
     
    CharlesBarros and theolagendijk like this.
  47. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    55
    Hi,
    i managed to contact Joe Maffei from Vuforia support, here is his answer (he was super helpful) regarding the Camera issue we have and some info about delayed loading (init-reinit vuforia) inside the same scene.

    It’s going to be removed/modified to work going forward in the next release.

    Here is what I have regarding your last issue:
    If using Delayed Initialization in Vuforia Config. Have you Vuforia Behaviour script de-activated in the scene. When you're ready to initialize Vuforia for the first time, run these two lines of code:
    VuforiaRuntime.Instance.InitVuforia();
    VuforiaBehaviour.Instance.enabled = true;

    Then, disable it with:
    VuforiaBehaviour.Instance.enabled = false;

    Then, any subsequent enabling after the first, only run this line:
    VuforiaBehaviour.Instance.enabled = true;
     
    theolagendijk likes this.
  48. daniil-b

    daniil-b

    Joined:
    Sep 23, 2015
    Posts:
    1
    Three months later and still no update, unbelievable.
     
    Railon23 and theolagendijk like this.
  49. David-Filipe

    David-Filipe

    Joined:
    May 19, 2015
    Posts:
    1
    Still no solution after three months, it is impossible to work like this!
     
    theolagendijk likes this.
  50. henriqueranj

    henriqueranj

    Joined:
    Feb 18, 2016
    Posts:
    96
    It worries me how long Vuforia support takes to solve critical issues.

    They are taking forever to solve this current problem of the project-wide initialisation and the camera feed lagging on Android when something overlays the app (this one is hanging for more than 1 year - https://developer.vuforia.com/forum/issues-and-bugs/camera-lags-android). And these are project-breaking issues.

    I hope to hear something soon from the Vuforia team that is not the usual "we will release a fix for the next Unity beta version".
     
    RafayAli and theolagendijk like this.