Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: added various null checks #288

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public void Initialize(IGoap goap)

public void Disable()
{
if (this.goap.IsNull())
return;

if (this.goap?.Events == null)
return;

Expand Down
12 changes: 7 additions & 5 deletions Package/Runtime/CrashKonijn.Goap.Runtime/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading