Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Any changes to google cardboard implementation in the last 5 months?

Discussion in 'VR' started by lz7cjc, Oct 4, 2021.

  1. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    Hi
    my project has been on hold for the last 5 months. Do i need to be aware of any upgrades to VR implementation for google cardboard, either from Unity or the SDK?
    thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Highly unlikely. Pretty much nobody (including Google) does Cardboard anymore.
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    arfish and JoeStrout like this.
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well then, I stand corrected. :)
     
  5. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    @mgear thanks for the update. Does this fix the problem of toggling between 2d and VR mode? My app was crashing whenever i did this previously. Also does it include a replacement for GVRreticlepointer? So I can navigate in game in the editor?
    thanks for your efforts
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    most of the help is coming from this topic
    https://github.com/googlevr/cardboard/issues/140

    for testing in editor,
    have to make own script apparently, i'm using this: (left alt down and move mouse to rotate cam)
    https://github.com/UnityCommunity/U...ssets/Scripts/Camera/EditorCardboardCamera.cs

    reticle:
    i'm actually still in 1.6, haven't checked if better reticle got added,
    for the timer i used UI 360 slider image with small script that sets the fill amount.. (raycast to detect if hover over target)
    and for the circular white expanding part, i used old reticle code (the one that builds circular mesh and expands it from shader)

    2d/vr mode switch:
    i had crashing also, their main example for switching mode doesnt work..
    i'm using some messy code like, and app is set to NOT have vr enabled at start (so its disabled from xr settings)
    upload_2021-10-5_11-50-0.png
     
  7. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    thanks very much for that code - will give it a go... I have avoided upgrading to 2020 and am still on 2019.4.0f1... is that the best version to stick with?
    thanks
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    i'm definitely staying with 2019.4.x on this one,
    and in general, avoiding 2020/2021, editor feels too sluggish..
     
    lz7cjc likes this.
  9. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    just noticed this is an image - any chance you can share the text version? thanks
     
  10. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  11. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    Hi I have implemented this code and it works the first time but the app crashes when i try to go back into VR. Any ideas? (I had to comment out the cam.* lines as they gave up errors in my editor)

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.XR.Management;
    4.  
    5.  
    6. public class VRToggle : MonoBehaviour
    7. {
    8.  
    9.     public bool vrOn;
    10.  
    11.     public void Start()
    12.     {
    13.         if (vrOn)
    14.         {
    15.            StartCoroutine(VRStart());
    16.  
    17.         }
    18.         else
    19.         {
    20.             VRStop();
    21.         }
    22.     }
    23.     public  IEnumerator VRStart()
    24.     {
    25.         var xrManager = XRGeneralSettings.Instance.Manager;
    26.         if (!xrManager.isInitializationComplete)
    27.         {
    28.             yield return xrManager.InitializeLoader();
    29.             xrManager.StartSubsystems();
    30.             Screen.sleepTimeout = SleepTimeout.NeverSleep;
    31.  
    32.         }
    33.        
    34.     }
    35.     public void VRStop()
    36.     {
    37.         var xrManager = XRGeneralSettings.Instance.Manager;
    38.         if (xrManager.isInitializationComplete)
    39.         {
    40.             xrManager.StopSubsystems();
    41.             xrManager.DeinitializeLoader();
    42.  
    43.             //cam.ResetAspect();
    44.             //cam.fieldOfView = defaultFov;
    45.             //cam.ResetProjectionMatrix();
    46.             //cam.ResetWorldToCameraMatrix();
    47.             Screen.sleepTimeout = SleepTimeout.SystemSetting;
    48.         }
    49.  
    50.     }
    51. }
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    my app has xr disabled at start:
    upload_2021-10-7_13-42-53.png

    StartXR, not sure if much difference to yours:
    Code (CSharp):
    1. private IEnumerator StartXR()
    2. {
    3.     Debug.Log("Initializing XR...");
    4.     if (!XRGeneralSettings.Instance.Manager.isInitializationComplete) yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    5.     yield return 0;
    6.  
    7.     if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    8.     {
    9.         Debug.LogError("Initializing XR Failed.");
    10.     }
    11.     else
    12.     {
    13.         Debug.Log("Starting XR...");
    14.         XRGeneralSettings.Instance.Manager.StartSubsystems();
    15.     }
    16.  
    stopXR
    Code (CSharp):
    1. Debug.Log("Stopping XR...");
    2. if (XRGeneralSettings.Instance != null) XRGeneralSettings.Instance.Manager.StopSubsystems();
    3. Camera.main.ResetAspect();
     
  13. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    yes - that is unchecked at the start since user begins in 2d screens
    I swapped my code for your and now see this error when I try going back into VR
    Initializing XR Failed.
    UnityEngine.Debug:LogError(Object)
    <VRStart>d__2:MoveNext() (at Assets/MyStuff/Scripts/VRToggle.cs:33)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    Code (CSharp):
    1.  if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    2.         {
    3.             Debug.LogError("Initializing XR Failed.");
    4.         }
     
  14. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    (not sure if relevant but I haven't installed the latest SDK you linked to, primarily because I can't see a unitypackage file when i download). Do I need that installed? If so how do I do this without the package manager? thanks )
     
  15. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  16. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    ok did it that way but still get the same error - presumably this is why it is crashing... any ideas? NB I now can't enter VR mode when i install the app on phone (android). This is both with your code and mine
    any other ideas? thanks
     
  17. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    whats the error message in device log?
     
  18. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    with your code?
    Initializing XR Failed.
    UnityEngine.Debug:LogError(Object)
    <VRStart>d__2:MoveNext() (at Assets/MyStuff/Scripts/VRToggle.cs:33)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
     
  19. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    i have these packages and versions
    upload_2021-10-7_19-41-35.png
     
  20. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Hi, it looks like you are using 1.6.0. There are some bug fixes, and improvements in the new 1.8.0 plugin.
     
  21. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    2021-10-08 (3).png 2021-10-08 (2).png

    I can't see an option to upgrade XR plugin management.
     
  22. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    my errors:
    Initializing XR Failed.
    UnityEngine.Debug:LogError(Object)
    <VRStart>d__2:MoveNext() (at Assets/MyStuff/Scripts/VRToggle.cs:33)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    when i enter VR

    Code (CSharp):
    1. using System.Collections;
    2.  
    3. using UnityEngine;
    4. using UnityEngine.XR.Management;
    5.  
    6.  
    7. public class VRToggle : MonoBehaviour
    8. {
    9.  
    10.     public bool vrOn;
    11.  
    12.     public void Start()
    13.     {
    14.         if (vrOn)
    15.         {
    16.             StartCoroutine(VRStart());
    17.  
    18.         }
    19.         else
    20.         {
    21.             VRStop();
    22.         }
    23.     }
    24.  
    25.     private IEnumerator VRStart()
    26.     {
    27.         Debug.Log("Initializing XR...");
    28.         if (!XRGeneralSettings.Instance.Manager.isInitializationComplete) yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    29.         yield return 0;
    30.  
    31.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    32.         {
    33.             Debug.LogError("Initializing XR Failed.");
    34.         }
    35.         else
    36.         {
    37.             Debug.Log("Starting XR...");
    38.             XRGeneralSettings.Instance.Manager.StartSubsystems();
    39.         }
    40.  
    41.     }
    42.         //public IEnumerator VRStart()
    43.       // {
    44.         //Debug.Log("start vr");
    45.  
    46.         //var xrManager = XRGeneralSettings.Instance.Manager;
    47.         //if (!xrManager.isInitializationComplete)
    48.         //{
    49.         //    yield return xrManager.InitializeLoader();
    50.         //    xrManager.StartSubsystems();
    51.         //    Screen.sleepTimeout = SleepTimeout.NeverSleep;
    52.  
    53.         //}
    54.  
    55.  
    56.  
    57.     private void VRStop()
    58.         {
    59.             Debug.Log("Stopping XR...");
    60.             if (XRGeneralSettings.Instance != null) XRGeneralSettings.Instance.Manager.StopSubsystems();
    61.             Camera.main.ResetAspect();
    62.         }
    63.         //{
    64.         //Debug.Log("stopping vr");
    65.         //var xrManager = XRGeneralSettings.Instance.Manager;
    66.         //if (xrManager.isInitializationComplete)
    67.         //{
    68.         //    xrManager.StopSubsystems();
    69.         //    xrManager.DeinitializeLoader();
    70.  
    71.         //    //cam.ResetAspect();
    72.         //    //cam.fieldOfView = defaultFov;
    73.         //    //cam.ResetProjectionMatrix();
    74.         //    //cam.ResetWorldToCameraMatrix();
    75.         //    Screen.sleepTimeout = SleepTimeout.SystemSetting;
    76.         //}
    77.  
    78.    //}
    79. }
     
  23. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Hi, try this on line 27-28:
    Code (CSharp):
    1.   Debug.Log("Initializing XR...");
    2.             yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    And check "Cardboard XR Plugin, and uncheck "Initialize XR on Startup" in Project Settings/XR-Plug-in Management.
     
  24. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  25. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    thanks - so it looks like this:
    Code (CSharp):
    1. Debug.Log("Initializing XR...");
    2.         /*if (!XRGeneralSettings.Instance.Manager.isInitializationComplete)*/ yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    3.         yield return 0;
    (box unchecked on startup)

    I am also tring to use this code from the documentation
    Code (CSharp):
    1. Coroutine VRStart()
    2.     {
    3.         return StartCoroutine(startVRRoutine());
    4.         IEnumerator startVRRoutine()
    5.         {
    6.             // Add error handlers for both Instance and Manager
    7.             var xrManager = XRGeneralSettings.Instance.Manager;
    8.             if (!xrManager.isInitializationComplete)
    9.                 yield return xrManager.InitializeLoader();
    10.             if (xrManager.activeLoader != null)
    11.                 xrManager.StartSubsystems();
    12.             // Add else with error handling
    13.         }
    14.     }
    but how do i get the code to run? I thought you called ienumerators not coroutines?

    thanks
     
  26. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    and you have cardboard checked?
     
  27. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    I also tried the code that mgear posted adding in a bool to determine which function to run:
    Code (CSharp):
    1. using System.Collections;
    2.  
    3. using UnityEngine;
    4. using UnityEngine.XR.Management;
    5.  
    6.  
    7. public class startXR : MonoBehaviour
    8. {
    9.     public bool xrStart;
    10.     public void Start()
    11.     {
    12.         if (xrStart)
    13.         {
    14.             StartCoroutine(StartXR());
    15.         }
    16.         else
    17.         {
    18.             StopXR();
    19.         }
    20.     }
    21.  
    22.     public IEnumerator StartXR()
    23.     {
    24.         Debug.Log("Initializing XR...");
    25.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    26.  
    27.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    28.         {
    29.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    30.         }
    31.         else
    32.         {
    33.             Debug.Log("Starting XR...");
    34.             XRGeneralSettings.Instance.Manager.StartSubsystems();
    35.         }
    36.     }
    37.  
    38.     void StopXR()
    39.     {
    40.         Debug.Log("Stopping XR...");
    41.  
    42.         XRGeneralSettings.Instance.Manager.StopSubsystems();
    43.         XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    44.         Debug.Log("XR stopped completely.");
    45.     }
    46. }
    47.  
    I think this is the full error log entry:
    using System.Collections;

    using UnityEngine;
    using UnityEngine.XR.Management;


    public class startXR : MonoBehaviour
    {
    public bool xrStart;
    public void Start()
    {
    if (xrStart)
    {
    StartCoroutine(StartXR());
    }
    else
    {
    StopXR();
    }
    }

    public IEnumerator StartXR()
    {
    Debug.Log("Initializing XR...");
    yield return XRGeneralSettings.Instance.Manager.InitializeLoader();

    if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    {
    Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    }
    else
    {
    Debug.Log("Starting XR...");
    XRGeneralSettings.Instance.Manager.StartSubsystems();
    }
    }

    void StopXR()
    {
    Debug.Log("Stopping XR...");

    XRGeneralSettings.Instance.Manager.StopSubsystems();
    XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    Debug.Log("XR stopped completely.");
    }
    }
     
  28. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    yes!
     
  29. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
  30. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782

    In which line does it fail now? When running on the device.
     
  31. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    Code (CSharp):
    1.  if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    2.         {
    3.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    4.         }
     
  32. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    the error pops up at line 29 but not sure what is causing the error
     
  33. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Perhaps easiest then to start over with a brand new project, and make it run with the demo scene?
    When the basics is up and running, then disable the "Initialize VR on Startup" and put back this custom code.
     
  34. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    so i followed these instructions: https://developers.google.com/cardboard/develop/unity/quickstart
    built the app but when i launch it, it launches in 2d not VR - is that right? The documentation seems to suggest it should launch in 3d

    So i added the script:
    Code (CSharp):
    1. using System.Collections;
    2.  
    3. using UnityEngine;
    4. using UnityEngine.XR.Management;
    5.  
    6.  
    7. public class startXR : MonoBehaviour
    8. {
    9.     public bool xrStart;
    10.     public void Start()
    11.     {
    12.         if (xrStart)
    13.         {
    14.             StartCoroutine(StartXR());
    15.         }
    16.         else
    17.         {
    18.             StopXR();
    19.         }
    20.     }
    21.  
    22.     public IEnumerator StartXR()
    23.     {
    24.         Debug.Log("Initializing XR...");
    25.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    26.  
    27.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    28.         {
    29.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    30.         }
    31.         else
    32.         {
    33.             Debug.Log("Starting XR...");
    34.             XRGeneralSettings.Instance.Manager.StartSubsystems();
    35.         }
    36.     }
    37.  
    38.     void StopXR()
    39.     {
    40.         Debug.Log("Stopping XR...");
    41.  
    42.         XRGeneralSettings.Instance.Manager.StopSubsystems();
    43.         XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    44.         Debug.Log("XR stopped completely.");
    45.     }
    46. }
    47.  
    and start off with a 2d scene. When I run it in the editor I get this error on 2d:
    NullReferenceException: Object reference not set to an instance of an object
    startXR.StopXR () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/startXR.cs:42)
    startXR.Start () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/startXR.cs:18)

    and this when i switch to the HelloCardboard scene
    Please initialize Cardboard XR loader before calling this function.
    UnityEngine.Debug:LogError(Object)
    Google.XR.Cardboard.Api:UpdateScreenParams() (at Library/PackageCache/com.google.xr.cardboard@d9f0aa2eb0/Runtime/Api.cs:295)
    CardboardStartup:Update() (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/CardboardStartup.cs:70)

    2021-10-08 (8).png 2021-10-08 (3).png 2021-10-08 (2).png
     
  35. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    No..., the demo should launch in VR. Check the "Initialize XR on Startup" for that. You should probably look at the NullReferenceException, also. Dont think it belongs to the demo scene. Just follow the steps.
     
  36. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    Based on earlier posts I understood this had to be unchecked on launch.
    i have checked it and still get this error:
    Please initialize Cardboard XR loader before calling this function

    Can you help me fix that?
    thanks
     
  37. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    Please can someone help on this? I have been bouncing around forums and threads on this all weekend but have been unable to find a solution. I have tried on a new clean app and in my existing set up but just get the same errors: Please initialize Cardboard XR loader before calling this function.

    Coping the code from the Unity Documentation:
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. using UnityEngine.XR.Management;
    5.  
    6. public class ManualXRControl
    7. {
    8.     public IEnumerator StartXR()
    9.     {
    10.         Debug.Log("Initializing XR...");
    11.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    12.  
    13.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    14.         {
    15.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    16.         }
    17.         else
    18.         {
    19.             Debug.Log("Starting XR...");
    20.             XRGeneralSettings.Instance.Manager.StartSubsystems();
    21.         }
    22.     }
    23.  
    24.     void StopXR()
    25.     {
    26.         Debug.Log("Stopping XR...");
    27.  
    28.         XRGeneralSettings.Instance.Manager.StopSubsystems();
    29.         XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    30.         Debug.Log("XR stopped completely.");
    31.     }
    32. }
    33.  
    34.  
    Fails here:
    Code (CSharp):
    1.      if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    2.         {
    3.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    4.         }
    I have created a new 3D project and followed each line of the instructions. I am running 2019.4.31fi

    In Editor
    I have tried running the sample HelloWorldVR scene and get these errors. It doesn't matter if i check the Initialise XR on start up box:
    Please initialize Cardboard XR loader before calling this function.
    UnityEngine.Debug:LogError (object)
    Google.XR.Cardboard.Api:UpdateScreenParams () (at Library/PackageCache/com.google.xr.cardboard@d9f0aa2eb0/Runtime/Api.cs:295)
    CardboardStartup:Update () (at Assets/Samples/Google Cardboard XR Plugin for Unity/1.8.0/Hello Cardboard/Scripts/CardboardStartup.cs:70)

    If I comment out this line it stops the errors
    Api.UpdateScreenParams();

    In app
    If I comment out this line it stops the errors
    Api.UpdateScreenParams();
    If I leave the Initialise XR on startup un checked then it doesn't launch in split screen
    If I check the box then it launches in split screen but the view doesn't change as I move my head

    If I don't comment out
    Api.UpdateScreenParams();
    HelloWorldVR works

    So I tried copying over CardboardStartup into a new VR scene
    If I turn off the toggle for Initialise XR on start up box start with a 2D screen then switch to VR, it remains in 2D it doesn't go split screen
    If I leave that toggle on and only launch my VR scene it still stays in 2D
    So I tried adding the toggle script and that made no difference.


    Is there no definitive answer on this? It seems a fair few people have hit the same problem. According to this post it was fixed about a year ago so should be part of the 1.8.0 plugin?
    https://github.com/googlevr/cardboard/issues/98


    This is doing my head and any help in resolving once and for all would be much appreciated
    thanks
     
  38. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782

    How about breaking up the StartXR into a method, thats starts Coroutine? Like this:

    Code (CSharp):
    1. bool vron;
    2. public void StartXR() {
    3.    StartCouroutine(StartXRRoutine());
    4. )
    5.  
    6. public IEnumerator StartXRRoutine()
    7.     {
    8.         if (vron)
    9.             yield break;
    10.  
    11.         vron = true;
    12.         Debug.Log("Initializing XR...");
    13.         yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    14.         if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    15.         {
    16.             Debug.LogError("Initializing XR Failed. Check Editor or Player log for details.");
    17.             vron = false;
    18.         }
    19.         else
    20.         {
    21.             Debug.Log("Starting XR...");
    22.             XRGeneralSettings.Instance.Manager.StartSubsystems();
    23.         }
    24.     }

    And add vron = false; to the StopXR() method.
     
  39. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    i tested the sample scenes from 1.8 in empty project, switch between 2d/3d worked,
    i think it had the error message "initialize first before calling", but no crash.

    then used my vrmanager code above, to switch and fix aspect ratio, no crash, no error messages, and did disable initial VR mode, so it starts in 2D.

    (samsung s10e)
     
  40. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    I wish I could do that! I have tested on Motorola Moto G(7) and do not get this result. When you say you can switch between VR and 2d in the test project, do you mean you set up new 2d scene and added in your code? "i tested the sample scenes from 1.8 in empty project, switch between 2d/3d worked," I only see two scenes in sample project HelloCardboard VR and VrMode which I believe are both in 3D?

    I have added 2d scenes to switch between but perhaps this was unnecessary?
     
  41. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    VrMode scene: yeah i meant "2D" as in no-vr.

    I'll upload the project to github later, so can test.
     
  42. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    @mgear -thank you that would be awesome
     
  43. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Last edited: Oct 12, 2021
  44. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  45. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    thanks but when I download the zip file it is empty - when I look in the folders unders "assets" I don't see Test VRMode.scene when i traverse the directory structure on github, or any scripts
    any ideas?
    thanks
     
  46. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
  47. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    this is the output of the logger when I run my code on my phone:
    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Starting XR...
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    <StartXR>d__2:MoveNext()
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 39)


    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> [XR] [CardboardXrInputProvider]: Lifecycle started

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> [XR] [CardboardXrDisplayProvider]: Initializes Cardboard API.

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> NativeCrashSerializer::EndReport() Success!


    any help?
    thanks
     
  48. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    Got it :) i have built and loaded the scene in 2D. When I choose the switch to VR button nothing happens. I assume it should go to split screen?

    This is an extract from the log when i try to select each button

    Refresh completed in 0.020778 seconds.
    RefreshInfo: RefreshV2(ForceSynchronousImport)
    RefreshProfiler: Total: 20.006ms
    InvokeBeforeRefreshCallbacks: 0.529ms
    ApplyChangesToAssetFolders: 0.044ms
    WriteModifiedImportersToTextMetaFiles: 0.000ms
    CleanLegacyArtifacts: 0.000ms
    Scan: 17.614ms
    OnSourceAssetsModified: 0.000ms
    UnregisterDeletedAssets: 0.000ms
    InitializeImportedAssetsSnapshot: 0.878ms
    GetAllGuidsForCategorization: 0.000ms
    CategorizeAssets: 0.000ms
    ImportAndPostprocessOutOfDateAssets: 0.000ms (0.000ms without children)
    ImportManagerImport: 0.000ms (0.000ms without children)
    ImportInProcess: 0.000ms
    ImportOutOfProcess: 0.000ms
    UpdateCategorizedAssets: 0.000ms
    RemoteAssetCacheGetArtifact: 0.000ms (0.000ms without children)
    RemoteAssetCacheResolve: 0.000ms
    RemoteAssetCacheDownloadFile: 0.000ms
    CompileScripts: 0.000ms
    PostProcessAllAssets: 0.000ms
    ReloadImportedAssets: 0.000ms
    VerifyAssetsAreUpToDateAndCorrect: 0.000ms
    EnsureUptoDateAssetsAreRegisteredWithGuidPM: 0.000ms
    InitializingProgressBar: 0.000ms
    PostProcessAllAssetNotificationsAddChangedAssets: 0.000ms
    OnDemandSchedulerStart: 0.000ms
    RestoreLoadedAssetsState: 0.000ms
    InvokeProjectHasChanged: 0.000ms
    UpdateImportedAssetsSnapshot: 0.000ms
    ReloadSourceAssets: 0.000ms
    UnloadImportedAssets: 0.000ms
    Hotreload: 0.019ms
    FixTempGuids: 0.003ms
    VerifyGuidPMRegistrations: 0.000ms
    GatherAllCurrentPrimaryArtifactRevisions: 0.044ms
    UnloadStreamsBegin: 0.036ms
    LoadedImportedAssetsSnapshotReleaseGCHandles: 0.089ms
    GetLoadedSourceAssetsSnapshot: 0.296ms
    PersistCurrentRevisions: 0.000ms
    UnloadStreamsEnd: 0.005ms
    GenerateScriptTypeHashes: 0.000ms
    Untracked: 0.448ms
    Refresh completed in 0.024681 seconds.
    RefreshInfo: RefreshV2(ForceSynchronousImport)
    RefreshProfiler: Total: 24.604ms
    InvokeBeforeRefreshCallbacks: 0.693ms
    ApplyChangesToAssetFolders: 0.042ms
    WriteModifiedImportersToTextMetaFiles: 0.000ms
    CleanLegacyArtifacts: 0.000ms
    Scan: 21.846ms
    OnSourceAssetsModified: 0.000ms
    UnregisterDeletedAssets: 0.000ms
    InitializeImportedAssetsSnapshot: 0.931ms
    GetAllGuidsForCategorization: 0.000ms
    CategorizeAssets: 0.000ms
    ImportAndPostprocessOutOfDateAssets: 0.000ms (0.000ms without children)
    ImportManagerImport: 0.000ms (0.000ms without children)
    ImportInProcess: 0.000ms
    ImportOutOfProcess: 0.000ms
    UpdateCategorizedAssets: 0.000ms
    RemoteAssetCacheGetArtifact: 0.000ms (0.000ms without children)
    RemoteAssetCacheResolve: 0.000ms
    RemoteAssetCacheDownloadFile: 0.000ms
    CompileScripts: 0.000ms
    PostProcessAllAssets: 0.000ms
    ReloadImportedAssets: 0.000ms
    VerifyAssetsAreUpToDateAndCorrect: 0.000ms
    EnsureUptoDateAssetsAreRegisteredWithGuidPM: 0.000ms
    InitializingProgressBar: 0.000ms
    PostProcessAllAssetNotificationsAddChangedAssets: 0.000ms
    OnDemandSchedulerStart: 0.000ms
    RestoreLoadedAssetsState: 0.000ms
    InvokeProjectHasChanged: 0.000ms
    UpdateImportedAssetsSnapshot: 0.000ms
    ReloadSourceAssets: 0.000ms
    UnloadImportedAssets: 0.000ms
    Hotreload: 0.026ms
    FixTempGuids: 0.004ms
    VerifyGuidPMRegistrations: 0.000ms
    GatherAllCurrentPrimaryArtifactRevisions: 0.086ms
    UnloadStreamsBegin: 0.034ms
    LoadedImportedAssetsSnapshotReleaseGCHandles: 0.097ms
    GetLoadedSourceAssetsSnapshot: 0.344ms
    PersistCurrentRevisions: 0.000ms
    UnloadStreamsEnd: 0.007ms
    GenerateScriptTypeHashes: 0.000ms
    Untracked: 0.495ms
    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerEnter of class Button
    Calling function OnPointerEnter with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerExit of class Button
    Calling function OnPointerExit with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerEnter of class Button
    Calling function OnPointerEnter with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerExit of class Button
    Calling function OnPointerExit with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerEnter of class Button
    Calling function OnPointerEnter with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerExit of class Button
    Calling function OnPointerExit with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerEnter of class Button
    Calling function OnPointerEnter with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerExit of class Button
    Calling function OnPointerExit with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerEnter of class Button
    Calling function OnPointerEnter with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> Failed to call function OnPointerExit of class Button
    Calling function OnPointerExit with no parameters but the function requires 1.
    CameraPointer:Update()

    [./Runtime/Mono/MonoBehaviour.cpp line 778]
    (Filename: ./Runtime/Mono/MonoBehaviour.cpp Line: 778)

    (Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> OnPointerClick:CubeRoomEnv
    CameraPointer:Update()
    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 39)


    <i>AndroidPlayer(motorola_moto_g(7)@192.168.18.5)</i> OnPointerClick:CubeRoomEnv
    CameraPointer:Update()
    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 39)
     
  49. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    did you click with gaze on the button, it should turn red, then click screen with finger?

    can ignore those "Calling function OnPointerExit with no parameters but the function requires 1." (the script is attached to button so it complaints about that)
     
  50. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    534
    doh - i only use gaze and pick so never occurred to me. So now this is what I get:
    A non split screen on loading - it is still controlled by moving the phone around to see the scene (not by dragging finger)
    I highlight the Enable VR button and tap on it and the screen splits
    I highlight the Disable VR button and tap on it and the screen goes back to full screen
    I can repeat this without the app crashing

    So I copied the script and the scene to my live project.
    I built with just this one scene
    I installed on my phone
    When I open the app, the full screen appears. But I can't move the screen, by rotating the phone and I can't tap the button to go into VR mode
    If I tap the enableVR button the app then crashes

    I built in debug mode but for some reason i can see the phone in the console but when I choose it it reverts to editor option

    So my assumption is that there is a problem with my environment but I have no idea where to look!
    2019.4.31f1
    iniitalise XR on startup unchecked
    XR plugin management 4.0.7
    I only have these packages installed:
    Subsystem registration
    Unity UI
    XR legacy input helpers
    XR plugin management

    any suggestions very gratefully received. I would rather avoid the nuclear option of migrating everything into a new project where the VR toggle works for many obvious reasons!

    thanks