diff --git a/NewHorizons/Builder/General/GroupsBuilder.cs b/NewHorizons/Builder/General/GroupsBuilder.cs index b2252f5e..2998c02f 100644 --- a/NewHorizons/Builder/General/GroupsBuilder.cs +++ b/NewHorizons/Builder/General/GroupsBuilder.cs @@ -25,5 +25,8 @@ public static class GroupsBuilder go.GetAddComponent()._sector = sector; go.GetAddComponent()._sector = sector; go.GetAddComponent()._sector = sector; + + // SectorCollisionGroup is unique among the sector groups because it only attaches its event listener on Start() instead of Awake(), so if the detail gets immediately deactivated then it never gets attached. To avoid this, we'll attach the event listener manually (even if it means getting attached twice). + sector.OnSectorOccupantsUpdated += go.GetComponent().OnSectorOccupantsUpdated; } } \ No newline at end of file diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 022acd74..825af0c1 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -356,7 +356,10 @@ namespace NewHorizons.Builder.Props singleLightSensor._sector.OnSectorOccupantsUpdated -= singleLightSensor.OnSectorOccupantsUpdated; } singleLightSensor._sector = sector; - singleLightSensor._sector.OnSectorOccupantsUpdated += singleLightSensor.OnSectorOccupantsUpdated; + if (singleLightSensor._sector != null) + { + singleLightSensor._sector.OnSectorOccupantsUpdated += singleLightSensor.OnSectorOccupantsUpdated; + } } } diff --git a/NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs new file mode 100644 index 00000000..39665dfc --- /dev/null +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Patches.EchoesOfTheEyePatches +{ + [HarmonyPatch(typeof(SingleLightSensor))] + public static class SingleLightSensorPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(SingleLightSensor.Start))] + public static void Start(SingleLightSensor __instance) + { + // SingleLightSensor assumes that the sector will be empty when it starts and disables itself, but this may not be true if it starts disabled and is activated later, or spawned via the API + if (__instance._sector && __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + { + __instance.OnSectorOccupantsUpdated(); + } + } + } +}