I have a behavior tree:
Sometimes, when deploying flares, I get an error:
I'm not sure why the bug happens. It seems to happen almost randomly at the Deploy Flares task.
The current code for the Deploy Flares task:
Sometimes, when deploying flares, I get an error:
If I remove the Cooldown decorator, I no longer get that error.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick () (at <58623c9461324266a5b7839460bb9d26>:0)
BehaviorDesigner.Runtime.BehaviorManager.Update () (at <58623c9461324266a5b7839460bb9d26>:0)
I'm not sure why the bug happens. It seems to happen almost randomly at the Deploy Flares task.
The current code for the Deploy Flares task:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
[TaskDescription("Deploy flares.")]
[TaskCategory("Pawn")]
public class DeployFlares : Action
{
private Pawn pawn;
private EnemyController controller;
public override void OnAwake()
{
pawn = GetComponent<Pawn>();
controller = GetComponent<EnemyController>();
}
public override void OnStart()
{
}
public override void OnBehaviorRestart()
{
}
public override TaskStatus OnUpdate()
{
if (!pawn || !controller) { return TaskStatus.Failure; }
pawn.DeployFlare();
if(pawn.FlareBurstProgress > 0)
{
return TaskStatus.Running;
}
return TaskStatus.Success;
}
public override void OnEnd()
{
}
}