From f78b6855f2cafc9c010f824f34a52d97d83b598b Mon Sep 17 00:00:00 2001 From: brandonmousseau <52470509+brandonmousseau@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:11:13 -0700 Subject: [PATCH] Delay starting VR until scene loaded This change delays initializing VR code until the "start" scene is loaded, which signals that the game is actually at the menu screen. The "loading" scene that appears on screen isn't captured by the UI management, so while the game is loading the user is awkardly put in an empty Unity environment. --- ValheimVRMod/ValheimVRMod.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ValheimVRMod/ValheimVRMod.cs b/ValheimVRMod/ValheimVRMod.cs index e6694cfb8..d68453975 100644 --- a/ValheimVRMod/ValheimVRMod.cs +++ b/ValheimVRMod/ValheimVRMod.cs @@ -1,5 +1,6 @@ using BepInEx; using UnityEngine; +using UnityEngine.SceneManagement; using ValheimVRMod.VRCore; using ValheimVRMod.VRCore.UI; using ValheimVRMod.Utilities; @@ -22,6 +23,8 @@ public class ValheimVRMod : BaseUnityPlugin private GameObject vrGui; private GameObject BhapticsTactsuit; + private bool startVrExecuted = false; + void Awake() { _version = Info.Metadata.Version; VHVRConfig.InitializeConfiguration(Config); @@ -37,11 +40,7 @@ void Awake() { #if NONVRMODE LogInfo("Running non-VR mode companion mod!"); #endif - } - - void Start() - { - StartValheimVR(); + SceneManager.sceneLoaded += OnSceneLoaded; } void Update() @@ -62,6 +61,16 @@ void Update() #endif } + void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + LogDebug("OnSceneLoaded: " + scene.name); + if (!startVrExecuted && scene.name.Equals("start")) + { + StartValheimVR(); + startVrExecuted = true; + } + } + void StartValheimVR() { bool vrInitialized = false;