From 4b51b2953d780fba56fd9721b4a91f44d3f8fbfa Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 8 Oct 2025 03:03:45 +1300 Subject: [PATCH] Fix post-mapinit NPC exception (#40244) Ensure `NPCBlackboard.Owner` is set during startup --- Content.Server/NPC/Components/NPCComponent.cs | 1 + Content.Server/NPC/HTN/HTNComponent.cs | 1 + Content.Server/NPC/HTN/HTNSystem.cs | 1 + Content.Server/NPC/Systems/NPCSystem.cs | 6 +++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Content.Server/NPC/Components/NPCComponent.cs b/Content.Server/NPC/Components/NPCComponent.cs index b1d5bfcf5f..3b396f034e 100644 --- a/Content.Server/NPC/Components/NPCComponent.cs +++ b/Content.Server/NPC/Components/NPCComponent.cs @@ -9,4 +9,5 @@ public abstract partial class NPCComponent : SharedNPCComponent /// [DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))] public NPCBlackboard Blackboard = new(); + // TODO FULL GAME SAVE Serialize this } diff --git a/Content.Server/NPC/HTN/HTNComponent.cs b/Content.Server/NPC/HTN/HTNComponent.cs index 43b8a70785..d9b392ab14 100644 --- a/Content.Server/NPC/HTN/HTNComponent.cs +++ b/Content.Server/NPC/HTN/HTNComponent.cs @@ -24,6 +24,7 @@ public sealed partial class HTNComponent : NPCComponent /// [ViewVariables] public HTNPlan? Plan; + // TODO FULL GAME SAVE serialize this? /// /// How long to wait after having planned to try planning again. diff --git a/Content.Server/NPC/HTN/HTNSystem.cs b/Content.Server/NPC/HTN/HTNSystem.cs index 4d9e321dd9..7bfe432998 100644 --- a/Content.Server/NPC/HTN/HTNSystem.cs +++ b/Content.Server/NPC/HTN/HTNSystem.cs @@ -33,6 +33,7 @@ public sealed class HTNSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(_npc.OnMobStateChange); SubscribeLocalEvent(_npc.OnNPCMapInit); + SubscribeLocalEvent(_npc.OnNPCStartup); SubscribeLocalEvent(_npc.OnPlayerNPCAttach); SubscribeLocalEvent(_npc.OnPlayerNPCDetach); SubscribeLocalEvent(OnHTNShutdown); diff --git a/Content.Server/NPC/Systems/NPCSystem.cs b/Content.Server/NPC/Systems/NPCSystem.cs index 27b2a1691d..7aea766930 100644 --- a/Content.Server/NPC/Systems/NPCSystem.cs +++ b/Content.Server/NPC/Systems/NPCSystem.cs @@ -63,9 +63,13 @@ namespace Content.Server.NPC.Systems WakeNPC(uid, component); } - public void OnNPCMapInit(EntityUid uid, HTNComponent component, MapInitEvent args) + public void OnNPCStartup(EntityUid uid, HTNComponent component, ComponentStartup args) { component.Blackboard.SetValue(NPCBlackboard.Owner, uid); + } + + public void OnNPCMapInit(EntityUid uid, HTNComponent component, MapInitEvent args) + { WakeNPC(uid, component); }