diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 4e27972b..5e8a1b2e 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -303,7 +303,7 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { if (controller != null) SunLightEffectsController.RemoveStar(controller); - if (!isProxy) SunLightEffectsController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); + if (!isProxy) SunLightEffectsController.RemoveStarLight(gameObject.FindChild("SunLight").GetComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/Stars/StarLightController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs similarity index 91% rename from NewHorizons/Components/Stars/StarLightController.cs rename to NewHorizons/Components/Stars/SunLightEffectsController.cs index c3c7b944..c5260e54 100644 --- a/NewHorizons/Components/Stars/StarLightController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Atmosphere; +using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -31,6 +32,13 @@ namespace NewHorizons.Components.Stars _sunLightParamUpdater._sunLightController = _sunLightController; } + public void Start() + { + // Using GameObject.Find here so that if its null we just dont find it + var sunlight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + if (sunlight != null) AddStarLight(sunlight); + } + public static void AddStar(StarController star) { if (star == null) return; @@ -58,16 +66,18 @@ namespace NewHorizons.Components.Stars public static void AddStarLight(Light light) { - if (light == null) return; - - Instance._lights.Add(light); + if (light != null) + { + Instance._lights.SafeAdd(light); + } } public static void RemoveStarLight(Light light) { - if (light == null) return; - - if (Instance._lights.Contains(light)) Instance._lights.Remove(light); + if (light != null && Instance._lights.Contains(light)) + { + Instance._lights.Remove(light); + } } public void Update() diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index b25e6d00..a170ff62 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -118,7 +118,7 @@ namespace NewHorizons.Handlers case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); SunLightEffectsController.RemoveStar(starController); - SunLightEffectsController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); + SunLightEffectsController.RemoveStarLight(ao.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 20e4a877..ef13942d 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -354,6 +354,7 @@ namespace NewHorizons var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; + // Fix the map satellite SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent();