InvalidOperationException are being thrown on 4.3.50

HI @aron_granberg,
After updating to 4.3.50 (and using 2021.2.14f1, wasn’t been able to test on other unity versions) I have noticed that there are InvalidOperationException being thrown if my agent script checks for the remaining distance in Update() for an agent that hasn’t moved yet (thus I don’t know if the lack of the movement is the reason). This wasn’t thrown before on 4.3.48.

InvalidOperationException: The cursor has been invalidated because SetPath has been called on the interpolator. Please create a new cursor.
Pathfinding.Util.PathInterpolator+Cursor.AssertValid () (at Library/PackageCache/com.arongranberg.astar@4.3.50/Core/Misc/PathInterpolator.cs:118)
Pathfinding.Util.PathInterpolator+Cursor.get_remainingDistance () (at Library/PackageCache/com.arongranberg.astar@4.3.50/Core/Misc/PathInterpolator.cs:75)
Pathfinding.AILerp.get_remainingDistance () (at Library/PackageCache/com.arongranberg.astar@4.3.50/Core/AI/AILerp.cs:282)
TestAIMovementScript.Update () (at Assets/TestAIMovementScript.cs:11)

Example agent script:

using System.Collections;
using System.Collections.Generic;
using Pathfinding;
using UnityEngine;

public class TestAIMovementScript : AILerp
{
    // Update is called once per frame
    void Update()
    {
        Debug.Log($"Remaining distance is: {remainingDistance}");
    }
}

Thanks!
I’ve fixed this locally and the fix will be included in the next version.

In the meantime, you should be able to check ai.hasPath and if it returns false, just assume the remaining distance is infinity.

1 Like