Search Unity

Unity 5.1.1 Oculus Integration - Coroutine yield and Application.LoadLevel causes camera to reorient

Discussion in 'AR/VR (XR) Discussion' started by InfiniteLee, Jul 14, 2015.

  1. InfiniteLee

    InfiniteLee

    Joined:
    Dec 11, 2014
    Posts:
    4
    Using the built in oculus integration in Unity 5.1.1, if you call Application.LoadLevel (or LoadLevelAsync) any time after a yield in a coroutine, it causes the camera to reorient it's rotation on all axis to (close to) zero- that is to say it will set the neutral rotation of the headset to be whatever the current orientation the headset is in.

    For example: if the headset is lying face down in front of you, rotated 45 degrees to the left. The camera will start with a rotation of approximately (90, 0, 45). Upon the call of LoadLevel, it "zeroes" out the rotation, causing the rotation of the camera to be approximately (0,0,0), while your actual view is wherever the headset happened to be pointed at the time. This can cause... discomfort.

    Example:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class changeScene: MonoBehaviour {
    6.     void Start () {
    7.         DontDestroyOnLoad(gameObject);
    8.         StartCoroutine(DoStuff());
    9.     }
    10.  
    11.     private IEnumerator DoStuff()
    12.     {
    13.         yield return new WaitForSeconds(3.0f);
    14.         Application.LoadLevelAsync("anotherscene");
    15.     }
    16. }
    However if you do the yield after the LoadLevel call, this bug does not occur.
    Code (CSharp):
    1.  
    2. private IEnumerator DoStuff()
    3. {
    4.     Application.LoadLevelAsync("anotherscene");
    5.     yield return new WaitForSeconds(3.0f);
    6. }
    7.  
    Furthermore, even if you try to call the LoadLevel outside of the coroutine, it still causes the bug to occur:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class changeScene: MonoBehaviour {
    6.     private bool doLoad = false;
    7.     private bool isLoading = false;
    8.  
    9.     void Start () {
    10.         DontDestroyOnLoad(gameObject);
    11.         StartCoroutine(DoStuff());
    12.     }
    13.  
    14.     private IEnumerator DoStuff() {
    15.         yield return new WaitForSeconds(3.0f);
    16.         doLoad = true;
    17.     }
    18.  
    19.     void Update () {
    20.         if (doLoad && !isLoading)
    21.         {
    22.             Application.LoadLevel("anotherscene");
    23.             isLoading = true;
    24.         }
    25.     }
    26. }
     
    Last edited: Jul 14, 2015
  2. williamj

    williamj

    Unity Technologies

    Joined:
    May 26, 2015
    Posts:
    94
    Hi InfiniteLee,

    Thanks for the detailed post. I will try to reproduce this issue and then pass it to the dev team. Can you please submit a bug report and post the case number here so we can track the progress of this issue?

    Thank you,
    Will
    Unity QA
     
    Last edited: Jul 14, 2015
  3. InfiniteLee

    InfiniteLee

    Joined:
    Dec 11, 2014
    Posts:
    4
    The case number is: 712152