StopAllCoroutines() gives a Null Reference Error.

Shiskebab

New member
When using StopAllCoroutines in an action i get a null reference error:

Code:
NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Runtime.Behavior.StopAllTaskCoroutines () (at <0ee4c5f576c0419f8ca527a83ecdbf9f>:0)
BehaviorDesigner.Runtime.Tasks.Task.StopAllCoroutines () (at <0ee4c5f576c0419f8ca527a83ecdbf9f>:0)
AttackMelee.OnUpdate () (at Assets/Scripts/Tasks/Action/AttackMelee.cs:39)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <0ee4c5f576c0419f8ca527a83ecdbf9f>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) (at <0ee4c5f576c0419f8ca527a83ecdbf9f>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick () (at <0ee4c5f576c0419f8ca527a83ecdbf9f>:0)
BehaviorDesigner.Runtime.BehaviorManager.Update () (at <0ee4c5f576c0419f8ca527a83ecdbf9f>:0)

What causes the error:
C#:
public override TaskStatus OnUpdate()
    {
        timeOut += Time.deltaTime;
        if (timeOut >= 0) {
            timeOut = Random.Range(-1.5f, -.7f);
            StopAllCoroutines();
            StartCoroutine(MeleeAttackSequence());
        }
        return TaskStatus.Running;
    }

    IEnumerator MeleeAttackSequence()
    {
        meleeTimer = 0f;
        while (meleeTimer < 1) {
            meleeTimer += Time.deltaTime;
            visuals.localPosition = new Vector3(0, 0, Mathf.PingPong(meleeTimer * Mathf.PI, 1.25f));
            yield return null;
        }
        meleeTimer = 0f;
        visuals.localPosition = Vector3.zero;
    }
 
Thanks - this is a problem when there aren't any coroutines to stop. I have it fixed and will send you an updated version.
 
Top