Last active
April 17, 2025 21:40
-
-
Save mrwellmann/aff41e21d958ada8a85aaddc8471fb8e to your computer and use it in GitHub Desktop.
When developing with a Meta Quest headset, this helps to prevent a black screen and the hourglass loading icon in the headset screen on application exit, and subsequent issues when re-entering play mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.XR.Management; | |
/// <summary> | |
/// Handles the initialization and deinitialization of XR subsystems in Unity. | |
/// </summary> | |
/// <remarks> | |
/// When developing with a Meta Quest headset, this helps to prevent a black screen and the hourglass loading icon in the headset screen on application exit, | |
/// and subsequent issues when re-entering play mode. | |
/// </remarks> | |
public class XRInitializer : MonoBehaviour | |
{ | |
private void Awake() | |
{ | |
if (XRGeneralSettings.Instance.Manager.activeLoader != null) | |
{ | |
XRGeneralSettings.Instance.Manager.StopSubsystems(); | |
XRGeneralSettings.Instance.Manager.DeinitializeLoader(); | |
} | |
XRGeneralSettings.Instance.Manager.InitializeLoaderSync(); | |
XRGeneralSettings.Instance.Manager.StartSubsystems(); | |
} | |
private void OnDisable() | |
{ | |
if (XRGeneralSettings.Instance.Manager.activeLoader != null) | |
{ | |
XRGeneralSettings.Instance.Manager.StopSubsystems(); | |
XRGeneralSettings.Instance.Manager.DeinitializeLoader(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment