Search Unity

Do not run Vufory when the application starts

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

  1. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    Getting the "It's not possible to have two ARCameras at the same time" as well. I fixed this error in the editor by putting everything in one scene and disabling it as needed. On the device this results in a black screen though.
     
  2. dpizzle

    dpizzle

    Joined:
    Feb 2, 2013
    Posts:
    28
    henriqueranj, I'm pretty bummed about the general slowness too, but I've read in the past that both these issues were on Unity's side and they can't fix it until Unity fixes some things under the hood.
     
  3. Marc-Uberstein

    Marc-Uberstein

    Joined:
    Apr 10, 2013
    Posts:
    8
    I made a little fix, but still with some extra effort.

    Just add "VuforiaBehaviour" Component to the Camera's you don't want as ARCamera, and the disable the Component (Uncheck the check mark).

    My code below should avoid auto ARCamera inits, and remove the existing "VuforiaBehaviour" Components to avoid the "It's not possible to have two ARCameras at the same time" error - and make it possible to spawn an ARCamera via developer request.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using UnityEngine.SceneManagement;
    4. using Vuforia;
    5.  
    6. public class FixARCameras : MonoBehaviour
    7. {
    8.     private List<Camera> _cameras = new List<Camera>();
    9.  
    10.     private VuforiaBehaviour _vuforiaBehaviour;
    11.  
    12.     private void OnEnable()
    13.     {
    14.         SceneManager.sceneLoaded += FixCameras;
    15.     }
    16.  
    17.     private void OnDisable()
    18.     {
    19.         SceneManager.sceneLoaded -= FixCameras;
    20.     }
    21.  
    22.     void FixCameras(Scene scene, LoadSceneMode mode)
    23.     {
    24.         _cameras.AddRange(Camera.allCameras);
    25.  
    26.         foreach (var c in _cameras)
    27.         {
    28.             _vuforiaBehaviour = c.GetComponent<VuforiaBehaviour>();
    29.  
    30.             if (_vuforiaBehaviour != null && !_vuforiaBehaviour.enabled)
    31.             {
    32.                 Destroy(_vuforiaBehaviour);
    33.             }
    34.  
    35.             _vuforiaBehaviour = null;
    36.         }
    37.  
    38.         _cameras.Clear();
    39.     }
    40. }
    41.  
     
  4. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    Thanks Marc, this technically works, but I get a black screen where the camera image should be.

    I should say that I also work with Google Cardboard and switch between VR and non-VR mode, so it might be on Cardboards end. I got it to work properly in a single scene though.
     
  5. Marc-Uberstein

    Marc-Uberstein

    Joined:
    Apr 10, 2013
    Posts:
    8
    Pleasure Jjoebstl - You should add the script on every scene, or add "don't destroy on load" and create a singleton.
     
  6. caiovm

    caiovm

    Joined:
    Aug 9, 2012
    Posts:
    4
    Hello guys,

    My fellow colleague @CharlesBarros and I came up with a simpler way to prevent Vuforia to attach the unwanted VuforiaBehaviour to our innocent Cameras.

    The workaround does not demand more than attaching the component VuforiaCameraIssueFix to a GameObject in your first scene.

    It worked flawlessly for our project (we are using Unity 2017.3.0p2). It even fixed the "black screen" camera issue. We tested on Unity Editor, iOS and Android. I hope it helps you guys.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using UnityEngine.SceneManagement;
    4. using Vuforia;
    5. using System.Reflection;
    6. using System;
    7.  
    8. public class VuforiaCameraIssueFix : MonoBehaviour
    9. {
    10.     void Awake()
    11.     {
    12.         try
    13.         {
    14.             EventInfo evSceneLoaded = typeof(SceneManager).GetEvent("sceneLoaded");
    15.             Type tDelegate = evSceneLoaded.EventHandlerType;
    16.  
    17.             MethodInfo attachHandler = typeof(VuforiaRuntime).GetMethod("AttachVuforiaToMainCamera", BindingFlags.NonPublic | BindingFlags.Static);
    18.  
    19.             Delegate d = Delegate.CreateDelegate(tDelegate, attachHandler);
    20.             SceneManager.sceneLoaded -= d as UnityEngine.Events.UnityAction<Scene, LoadSceneMode>;
    21.         }
    22.         catch (Exception e)
    23.         {
    24.             Debug.LogWarning("Cant remove the AttachVuforiaToMainCamera action: " + e.ToString());
    25.         }
    26.     }
    27. }
    As you can notice we were forced to use reflection to unsubscribe the Vuforia's method AttachVuforiaToMainCamera from SceneManager.sceneLoaded, that was causing the problem.


    Cheers
     
    Last edited: Jan 19, 2018
  7. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    Alright the blackscreen issue was due to the Digital Eyewear settings of Vuforia... for anyone experiencing the same issue this is how I fixed it:


    Code (CSharp):
    1.        if (newDevice == "None" || newDevice == "")
    2.         {
    3.             Debug.Log("Changed to AR.");
    4.             XRSettings.enabled = false;
    5.             DigitalEyewearARController.Instance.SetEyewearType(DigitalEyewearARController.EyewearType.None);
    6.             DigitalEyewearARController.Instance.SetMode(Device.Mode.MODE_AR);
    7.             DigitalEyewearARController.Instance.SetViewerActive(false, true);
    8.         }
    9.         else
    10.         {
    11.             Debug.Log("Changed to VR.");
    12.             XRSettings.enabled = true;
    13.             if (CameraDevice.Instance.Stop() && CameraDevice.Instance.Deinit())
    14.             {
    15.                 DigitalEyewearARController.Instance.SetEyewearType(DigitalEyewearARController.EyewearType.VideoSeeThrough);
    16.                 DigitalEyewearARController.Instance.SetMode(Device.Mode.MODE_VR);
    17.                 DigitalEyewearARController.Instance.SetViewerActive(true, true);
    18.             }
    19.         }
     
  8. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Hey all,

    Chiming in again to let everyone know that a fix for this has been addressed for an upcoming release. I will update this thread again with the exact version when possible.

    Thank you all for your patience
     
  9. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    Looking forward to it! Vuforia currently feels like a fragile little flower, it looks great but is easily broken.
     
  10. kmsuzanna

    kmsuzanna

    Joined:
    Nov 10, 2016
    Posts:
    2
    Not being allowed to start and stop vuforia is totally ridiculous. Spent a good hour trying to get information from the documentation which is useless.
     
    Railon23 likes this.
  11. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    231
    Even after deleting the Resources folder and the Vuforia folder from the assets AND building the library (this re-created the resources folder), Vuforia is launched when hitting Play Mode. What is this?
     
  12. henriqueranj

    henriqueranj

    Joined:
    Feb 18, 2016
    Posts:
    138
    @F-R-O-S-T-Y have you tried disabling Vuforia under XR Settings in the Player Settings for the platform you're targeting?
     
  13. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    231
    Yes, I did. But this setting got reset when re-building the library folder. And disabling the option didn't stop Vuforia from executing.

    The project I tried Vuforia on, was luckily a copy of my original project. So I deleted the project with Vuforia and created it again, without adding Vuforia to it. This resolved the issue.
     
  14. 13889264826

    13889264826

    Joined:
    Dec 11, 2017
    Posts:
    6
    hello,I got the same problem,are there have any solution for this problem?
     
  15. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    There are several solutions to this problem in this thread, all of them are kinda hacky though but at least they work. We will have to wait for Vuforia to fix this issue.
     
  16. atorisa

    atorisa

    Joined:
    Dec 1, 2013
    Posts:
    122
    2018.1 is fixing this bug?
     
  17. FejZa

    FejZa

    Joined:
    Sep 9, 2015
    Posts:
    21
    Can't believe this is taking so long! Don't you guys at Vuforia understand this is making it close to impossible to use Vuforia in applications that go beyond having a single scene and camera?

    Just remove / comment out whatever the 4 or 5 lines of code are that automaatically attach to the MainCamera and leave it alone! I can't believe how many hours have been spent on this by others to find workarounds. This should be addressed by you guys as a HOTFIX, like really really HOT.
     
    anthodb, Railon23 and henriqueranj like this.
  18. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    53
    I can confirm that building for Android with Vuforia enabled, even when asking for Delayed initialization, the following lines are added to the AndroidManifest during build postprocess:

    <uses-feature android:glEsVersion="0x00020000"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-feature android:name="android.hardware.location.gps" android:required="false"/>
    <uses-feature android:name="android.hardware.location" android:required="false"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera" android:required="true"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
    <uses-permission android:maxSdkVersion="18" android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false"/>
    <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
    <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false"/>
    <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <meta-data android:name="android.support.VERSION" android:value="25.3.1"/>


    This means that even if we don't call Vuforia init() when the app starts up, the user is still prompted with two permissions: 1) to track user's locationd and 2) to take pictures and video. This is a big problem because some apps like ours only offer AR experiences as a small subset of the app, and goes against current Android best-practices regarding permissions (ie do not ask for permissions before and if they are required).
     
    Last edited: Mar 9, 2018
  19. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    765
    Yeah, we couldn't fix the issue on our end until we switched to asset bundles. Using the OBB extension file caused the camera permission to always show no matter what.
     
  20. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    53
    Sorry, what do you mean that you switched to asset bundles? How would that remove the permissions request when the app launches?
     
  21. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    Hey Strasza, any news about the official fix?
    As we pointed out, is not that hard for you guys change this undesired behaviour.
     
    Railon23 likes this.
  22. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    55
    Hi this proposal throws errors once you try to build for the UWP Hololens device. Have you beeing able to deploy anywhere @caiovm ?
    upload_2018-3-12_18-40-10.png

     
    Last edited: Mar 12, 2018
  23. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    765
    It was an issue with split application binary. I'm not sure why, but without splitting the binary we were able to disable the permissions popup and request manually through this handy plugin: https://github.com/Over17/UnityAndroidPermissions. As soon as we needed to split the app, Vuforia seemed to request the permission no matter what. We switched to asset bundles to get filesize down instead of the split binary option and that solved the issue.
     
  24. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    The fact that this issue still hasn't been addressed is starting to get on my nerves.

    When I load an additional scene, while I still have a camera in my current (DontDestroyOnLoad) scene it just tags that one as MainCamera and proceeds to attach all kinds of Vuforia related behaviors to it...

    This is just incredibly poor design on the side of Vuforia and I have no idea who came up with the idea to build it so persistently annoying.
     
  25. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    Yes, this is changed in 2018.1 with Vuforia 7.1.
     
    ankitdce14591 and RafayAli like this.
  26. su9257

    su9257

    Joined:
    Jun 13, 2017
    Posts:
    16
    I think this is a very bad problem. Once you enter unity, vuforia will be automatically initialized, and it can't be stopped at all. The current version used is 2017.3.1 p4, because sometimes I don't use Vuforia at all, which will make Unity The slow start, the most serious problem is that I deleted all vuforia resources, but he can start! My God, this is a bit like a virus! Hope to fix this problem quickly, thank you very much~:confused::eek:o_O
     
  27. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    This fix still works and we are using this in production since the date of the post (Android and iOS).
    Which Unity version you are using?
     
  28. SpaceScientist

    SpaceScientist

    Joined:
    Mar 7, 2018
    Posts:
    7
    Jjoebstl, where did you attach this code? I don't see a script attached to the digital eyewear and I can't seem to edit the Vuforia behaviour script.
     
  29. SpaceScientist

    SpaceScientist

    Joined:
    Mar 7, 2018
    Posts:
    7
    Charles, I tried a very similar script in my project and it was working for when the world center mode was first-image tracking. But the second I switched device-tracking mode (it's not really switching between the different modes either btw. I'm not sure if others are aware of this problem), it stopped working and a black screen+the vuforia camera is showing up in my non-AR scenes.
     
  30. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    It's just a function in a manager script I wrote. My current issue is that this seems to only work in Development builds... like I said before due to this issue Vuforia+Cardboard are borderline impossible to use in any real world application...

    I will try to update to the Unity 2018 beta this friday and see it if fixes anything.
     
  31. SpaceScientist

    SpaceScientist

    Joined:
    Mar 7, 2018
    Posts:
    7
    I'm running into the same problem with whatever I've tried. Works fine until I build my app. Sigh. my thesis is due on friday and IDK if I'll have a working product.
     
  32. Jjoebstl

    Jjoebstl

    Joined:
    Jan 10, 2018
    Posts:
    9
    My only advice is to try it in a development build. I will look into a workaround for the release build tomorrow.

    https://github.com/googlevr/gvr-unity-sdk/issues/661 indicates that it is an OpenGLES issue.
     
  33. SpaceScientist

    SpaceScientist

    Joined:
    Mar 7, 2018
    Posts:
    7
    I'm currently rolling back to Vuforia 6.0 on one of the university computers and trying out the same scenes there. I'm not very hopeful but I needed to try something
     
  34. SpaceScientist

    SpaceScientist

    Joined:
    Mar 7, 2018
    Posts:
    7
    Update: in Vuforia 6.0, the world center modes do change between different scenes (unlike the new Vuforia) but somehow the device tracking mode still manages to mess up every single scene you visit after it.
     
  35. dpaskarina

    dpaskarina

    Joined:
    Oct 22, 2015
    Posts:
    4
    Will Vuforia 7.1 update also be included to unity LTS line (2017.4)? Current LTS version still uses 7.0 version and still has this problem. It's very counter-intuitive to add vuforia behaviour to camera and turn it off in every scene to disable vuforia for that scene.
     
    GoranRiddle, JoRangers and atorisa like this.
  36. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @dpaskarina We won't pull 7.1 into the LTS line, but we may patch this specific fix into 7.0 for the LTS build. I'll update the forums if this happens.
     
  37. V-Jankaitis

    V-Jankaitis

    Joined:
    Nov 12, 2014
    Posts:
    4
    Why not provide simple Vuforia.Start() and Vuforia.Stop() instead of asking used to write lines and lines of code to disable things you are keep enabling? No app need AR screen in every screen. It`s a massive overlook and lack of care.
     
    Railon23 and ashleyjamesbrown like this.
  38. ashleyjamesbrown

    ashleyjamesbrown

    Joined:
    May 23, 2018
    Posts:
    9
    Is this fixed yet ?
     
  39. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    This is resolved in Vuforia 7.1.
     
    ashleyjamesbrown likes this.
  40. ashleyjamesbrown

    ashleyjamesbrown

    Joined:
    May 23, 2018
    Posts:
    9
    So is there now methods we can call to enable and disable vuforia within the same scene or do we just load in an AR Camera and it will fire up vuforia and if we disable or setactive =false it will unload and return to our previous state. ?

    Im asking as mostly my scene does not involve vuforia and i have a button to activate the camera and a close to turn it off which i am hoping will work now properly ?
     
  41. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    332
    It doesn't look like it is on my end. Unfortunately, the workarounds posted in this thread don't work either. This is a bit of a bummer.
     

    Attached Files:

  42. GoranRiddle

    GoranRiddle

    Joined:
    Dec 10, 2015
    Posts:
    1
    You should patch the fix on the LTS build, since as the page says:

    Issues like this very one.
     
  43. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    332
    Any word on 7.1.34 still having this issue, @Vuforia-Strasza? This really needs fixing ASAP.
     
  44. Vuforia-Strasza

    Vuforia-Strasza

    Official Vuforia Employee Vuforia

    Joined:
    Jun 13, 2017
    Posts:
    548
    @Thomas-Mountainborn How is your scene setup?

    Are you getting an ARCamera automatically added in a scene that otherwise has no Vuforia objects?
     
  45. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    332
    I start with a scene with 2 cameras: a camera which does the UI, and a separate AR camera. AR is only used for a small section of the application, it's mostly just all UI.

    Once a second scene is loaded additively (without any AR behaviours), the UI camera of the main scene gets the Vuforia behaviour added, and the error is thrown 7 times. The cameras in the second scene are left untouched.

    The UI camera in the main scene which gets the unwanted Vuforia behaviours is not marked as main camera, I specifically tagged the AR camera as main camera in a vain hope of tricking the system. However, Vuforia also tags the UI camera as MainCamera as soon as the second scene is loaded, and proceeds to add its behaviours.
     
  46. shubh143

    shubh143

    Joined:
    Jun 1, 2017
    Posts:
    4
    YEAH IT'S WORKING THANKS A LOT MAN
     
  47. shubh143

    shubh143

    Joined:
    Jun 1, 2017
    Posts:
    4
    HOW TO RECORD GRAPHIC OVERLAY AND CAMERA IN VUFORIA?
     
  48. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    I have a number of cameras in my scene, 1 is an AR camera and has the VuforiaBehaviour script on it disabled.
    Delayed Initialisation is checked in configuration. Vuforia version 7.2.23
    I'm still getting the "It's not possible to have two ARCameras at the same time" error. On investigation it is searching out an untagged camera that is named "Background". It's the first camera in my scene. On start it immediately tags it Main camera and goes ahead and starts adding Vuforia Video background and Default initialisation behaviours to it.
    If I manually add the VuforiaBehaviour script to it and disable it doesn't add all the scripts but I still get the same error.

    Unity version 2018.1.6
     
  49. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,496
    I found the answer.
    As I didn't want the AR camera rendering at startup I disabled the camera component. That seems to cause Vuforia to then go off and try and use another camera.
    I have to wait for the initialisation phase to end and then disable the camera via a script.

    Still seems a very painful process to simply delay the start of the AR affect.
     
  50. walassousa

    walassousa

    Joined:
    Nov 13, 2018
    Posts:
    1
    Hello you managed to solve the problem is that Vuforia automatically turns on when the application is started. I created my game in which I use a normal camera and another AR, but when I start the app it goes directly to the camera of AR vuforia, could I solve this problem? Thank you very much in advance