From 0186f5ee23706092ea54083b4a6942cb8ba0e16b Mon Sep 17 00:00:00 2001 From: Indigocoder1 Date: Tue, 24 Dec 2024 13:15:31 -0800 Subject: [PATCH] Added scene loaded event to reload materials --- Nautilus/Utility/MaterialUtils.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Nautilus/Utility/MaterialUtils.cs b/Nautilus/Utility/MaterialUtils.cs index 7dbd9e8e..8c146ac8 100644 --- a/Nautilus/Utility/MaterialUtils.cs +++ b/Nautilus/Utility/MaterialUtils.cs @@ -1,6 +1,7 @@ using Nautilus.Utility.MaterialModifiers; using System.Collections; using UnityEngine; +using UnityEngine.SceneManagement; using UWE; namespace Nautilus.Utility; @@ -11,10 +12,16 @@ namespace Nautilus.Utility; public static partial class MaterialUtils { private static readonly int _emissionMap = Shader.PropertyToID("_EmissionMap"); + private static bool _sceneEventAdded; internal static void Patch() { CoroutineHost.StartCoroutine(LoadReferences()); + if (!_sceneEventAdded) + { + SceneManager.sceneLoaded += OnSceneLoaded; + _sceneEventAdded = true; + } } private static IEnumerator LoadReferences() @@ -22,7 +29,7 @@ private static IEnumerator LoadReferences() yield return PatchInternal(); IsReady = true; - + yield break; } @@ -249,7 +256,7 @@ public static void ApplyUBERShader(Material material, float shininess, float spe { material.EnableKeyword("MARMO_NORMALMAP"); } - + material.enableInstancing = true; material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack | MaterialGlobalIlluminationFlags.RealtimeEmissive; @@ -325,4 +332,11 @@ public static void SetMaterialCutout(Material material, bool cutout) material.DisableKeyword("MARMO_ALPHA_CLIP"); } } + + private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + if (scene.name != "MenuEnvironment") return; + + CoroutineHost.StartCoroutine(LoadReferences()); + } }