diff --git a/Package/Runtime/CrashKonijn.Goap.Runtime/Behaviours/GoapBehaviour.cs b/Package/Runtime/CrashKonijn.Goap.Runtime/Behaviours/GoapBehaviour.cs index 688d9705..92a8bfa4 100644 --- a/Package/Runtime/CrashKonijn.Goap.Runtime/Behaviours/GoapBehaviour.cs +++ b/Package/Runtime/CrashKonijn.Goap.Runtime/Behaviours/GoapBehaviour.cs @@ -32,12 +32,12 @@ private void Awake() private void Update() { - this.goap.OnUpdate(); + this.goap?.OnUpdate(); } private void LateUpdate() { - this.goap.OnLateUpdate(); + this.goap?.OnLateUpdate(); } private void OnDestroy() diff --git a/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ProactiveController.cs b/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ProactiveController.cs index 962d3b30..198f37e9 100644 --- a/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ProactiveController.cs +++ b/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ProactiveController.cs @@ -17,6 +17,12 @@ public void Initialize(IGoap goap) public void Disable() { + if (this.goap.IsNull()) + return; + + if (this.goap?.Events == null) + return; + this.goap.Events.OnAgentResolve -= this.OnAgentResolve; this.goap.Events.OnNoActionFound -= this.OnNoActionFound; } diff --git a/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ReactiveController.cs b/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ReactiveController.cs index cd97ae73..4d68d5b0 100644 --- a/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ReactiveController.cs +++ b/Package/Runtime/CrashKonijn.Goap.Runtime/Classes/Controllers/ReactiveController.cs @@ -15,6 +15,9 @@ public void Initialize(IGoap goap) public void Disable() { + if (this.goap.IsNull()) + return; + if (this.goap?.Events == null) return; diff --git a/Package/Runtime/CrashKonijn.Goap.Runtime/Extensions.cs b/Package/Runtime/CrashKonijn.Goap.Runtime/Extensions.cs index cdc3e62f..7c6910f2 100644 --- a/Package/Runtime/CrashKonijn.Goap.Runtime/Extensions.cs +++ b/Package/Runtime/CrashKonijn.Goap.Runtime/Extensions.cs @@ -10,12 +10,14 @@ namespace CrashKonijn.Goap.Runtime { public static class Extensions { - public static bool IsNull(this IMonoAgent agent) - => agent is MonoBehaviour mono && mono == null; - - public static bool IsNull(this IMonoGoapActionProvider actionProvider) - => actionProvider is MonoBehaviour mono && mono == null; + public static bool IsNull(this object obj) + { + if (obj is not MonoBehaviour mono) + return obj == null; + return mono == null; + } + public static string ToName(this Comparison comparison) { return comparison switch