Fix post-mapinit NPC exception (#40244)
Ensure `NPCBlackboard.Owner` is set during startup
This commit is contained in:
@@ -9,4 +9,5 @@ public abstract partial class NPCComponent : SharedNPCComponent
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
|
[DataField("blackboard", customTypeSerializer: typeof(NPCBlackboardSerializer))]
|
||||||
public NPCBlackboard Blackboard = new();
|
public NPCBlackboard Blackboard = new();
|
||||||
|
// TODO FULL GAME SAVE Serialize this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public sealed partial class HTNComponent : NPCComponent
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public HTNPlan? Plan;
|
public HTNPlan? Plan;
|
||||||
|
// TODO FULL GAME SAVE serialize this?
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long to wait after having planned to try planning again.
|
/// How long to wait after having planned to try planning again.
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public sealed class HTNSystem : EntitySystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<HTNComponent, MobStateChangedEvent>(_npc.OnMobStateChange);
|
SubscribeLocalEvent<HTNComponent, MobStateChangedEvent>(_npc.OnMobStateChange);
|
||||||
SubscribeLocalEvent<HTNComponent, MapInitEvent>(_npc.OnNPCMapInit);
|
SubscribeLocalEvent<HTNComponent, MapInitEvent>(_npc.OnNPCMapInit);
|
||||||
|
SubscribeLocalEvent<HTNComponent, ComponentStartup>(_npc.OnNPCStartup);
|
||||||
SubscribeLocalEvent<HTNComponent, PlayerAttachedEvent>(_npc.OnPlayerNPCAttach);
|
SubscribeLocalEvent<HTNComponent, PlayerAttachedEvent>(_npc.OnPlayerNPCAttach);
|
||||||
SubscribeLocalEvent<HTNComponent, PlayerDetachedEvent>(_npc.OnPlayerNPCDetach);
|
SubscribeLocalEvent<HTNComponent, PlayerDetachedEvent>(_npc.OnPlayerNPCDetach);
|
||||||
SubscribeLocalEvent<HTNComponent, ComponentShutdown>(OnHTNShutdown);
|
SubscribeLocalEvent<HTNComponent, ComponentShutdown>(OnHTNShutdown);
|
||||||
|
|||||||
@@ -63,9 +63,13 @@ namespace Content.Server.NPC.Systems
|
|||||||
WakeNPC(uid, component);
|
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);
|
component.Blackboard.SetValue(NPCBlackboard.Owner, uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnNPCMapInit(EntityUid uid, HTNComponent component, MapInitEvent args)
|
||||||
|
{
|
||||||
WakeNPC(uid, component);
|
WakeNPC(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user