Added null checks for AI blackboard data

- Null checks added to prevent AI causing the engine to crash
This commit is contained in:
mushgunAX 2022-11-25 11:44:58 +08:00
parent 4daaa8e897
commit c5d490b8b2
3 changed files with 14 additions and 2 deletions

View File

@ -41,7 +41,15 @@ public partial class LeafAttack : BehaviourTreeNode
onEnter(BehaviourTreeNodeStatus.RUNNING); onEnter(BehaviourTreeNodeStatus.RUNNING);
//Succeed when stand in hurt box for long enough //Succeed when stand in hurt box for long enough
float captureTime = (float)GetNodeData("captureTimeLeft"); //Debug.Log("Attempting to get blackboard data");
float? captureTime = (float?)GetNodeData("captureTimeLeft");
//Debug.Log("Got blackboard data");
if (captureTime == null)
{
status = BehaviourTreeNodeStatus.FAILURE;
onExit(BehaviourTreeNodeStatus.FAILURE);
return status;
}
captureTime -= Time.DeltaTimeF; captureTime -= Time.DeltaTimeF;
SetNodeData("captureTimeLeft", captureTime); SetNodeData("captureTimeLeft", captureTime);
//Debug.Log(captureTime.ToString()); //Debug.Log(captureTime.ToString());

View File

@ -119,7 +119,7 @@ public partial class LeafChase : BehaviourTreeNode
//Play SFX //Play SFX
if (GetNodeData("isCapturing") != null && (bool)GetNodeData("isCapturing") == false) if (GetNodeData("isCapturing") != null && (bool)GetNodeData("isCapturing") == false)
{ {
Debug.Log("AI Play capturing SFX"); //Debug.Log("AI Play capturing SFX");
} }
SetNodeData("isCapturing", true); SetNodeData("isCapturing", true);

View File

@ -84,6 +84,10 @@ public partial class LeafPatrol : BehaviourTreeNode
} }
waypoints = (List<GameObject>)GetNodeData("waypoints"); waypoints = (List<GameObject>)GetNodeData("waypoints");
if (waypoints == null)
{
return;
}
Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent<Transform>().GlobalPosition; Vector3 targetPosition = waypoints[currentWaypointIndex].GetComponent<Transform>().GlobalPosition;
//Reach waypoint by X and Z being near enough //Reach waypoint by X and Z being near enough