Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to properly restart the XR Session

Discussion in 'AR' started by AliCanKeskin, Aug 9, 2022.

  1. AliCanKeskin

    AliCanKeskin

    Joined:
    Jun 7, 2022
    Posts:
    17
    Hello, currently after a condition is satisfied a I create a new session and do my stuff from a native library (C++) but when I am done with that session I want to go back to Unity. Now, when I go to unity and make CreateSession if needed calls from the OpenXR library I do not render anything even if the program is working and I can get prints from Update function and other stuff. Do you know how can I properly initialize a new session inside Unity?
     
  2. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    399
    The OpenXRLoader c# class controls the OpenXR Session. You can get the loader via `XRGeneralSettings.Instance.Manager.activeLoader`. The call Stop() will end the session. DeInitialize() will Destroy the session. Initialize() will create the session. Start() will begin the session.
     
    andyb-unity and KyryloKuzyk like this.
  3. AliCanKeskin

    AliCanKeskin

    Joined:
    Jun 7, 2022
    Posts:
    17
    I tried nearly all of the combinations to stop/destroy and start/initialize the session but when I get back to Unity, I can start the session but I cannot see anything, nothing is rendered. Do you have any idea why this can happen?
     
  4. AliCanKeskin

    AliCanKeskin

    Joined:
    Jun 7, 2022
    Posts:
    17
    Ok, the thing is I call Stop() then Deinit() and initialize my own session in native side and it works. After my work is done in native side I move back to the Unity side and instantiate a prefab which is a UI Panel says I am done in the native side. In the Awake() of that prefab I call Init() then Start() (because it seems like you can call XRGeneralSettings.Instance.Manager.activeLoader.Init() only in a Start() or Awake() ). Then nothing happens and the program stops. Do you have any idea about why it stops completely ?
     
  5. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    399
  6. AliCanKeskin

    AliCanKeskin

    Joined:
    Jun 7, 2022
    Posts:
    17
    I have done this but
    Code (CSharp):
    1. yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
    this line does not return even though I've waited for 5-7 mins.
     
  7. AliCanKeskin

    AliCanKeskin

    Joined:
    Jun 7, 2022
    Posts:
    17
    I have tried using this and the previous method. But I could not manage start the Update() loop again. Once I stop and deinitialize (or stop systems and deinitialize, doesn't really matter) and do my stuff I cannot seem to be able to turn back to Unity. I have tried to call Initialize() and then Start() but it says you should call this on Awake() or Start(). But I cannot even reach to those states. I even tried loading a new scene, re-loading the current scene or initializing a object( in this one I could call these functions but it didn't change anything only void scene and it is running ?).While stopping and deinit()ing it completes that update() function and then I cannot restart it. I have tried to call the re-initialization functions from various callbacks, even callbacks from UWP's windows such as visibility changed, corewindow.Activated ... It does not work. I think I couldn't find the right time and place to call these functions. If you have any suggestions please let me know.