Problem with getting allNodes

I have this code on my OnPathComplete

ConstantPath constPath = p as ConstantPath;
List nodes = constPath.allNodes;

I am getting this error message

NullReferenceException: Object reference not set to an instance of an object
ConstantAIPath.OnPathComplete (Pathfinding.Path p) (at Assets/ConstantAIPath.cs:391)
Seeker.OnPathComplete (Pathfinding.Path p, Boolean runModifiers, Boolean sendCallbacks) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:306)
Seeker.OnPathComplete (Pathfinding.Path p) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:262)
Pathfinding.Path.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:702)
AstarPath.ReturnPaths (Boolean timeSlice) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2300)
AstarPath.Update () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:698)

What exactly does this mean?

I read in the documentation
“Then when getting the callback, all nodes will be stored in the variable ConstantPath.allNodes (remember that you need to cast it from Path to ConstantPath first to get the variable).”

But how exactly do I do this?

That means that the callback function was not called with a ConstantPath. Are you sure you are starting the ConstantPath in the correct way? (normal path requests are not ConstantPaths).

Thanks for the quick reply :slight_smile:

I called the constant path like this

ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, null);
mySeeker.StartPath (constPath);

I am assuming that the callback was handled by the seeker

I tried using
ConstantPath constPath = ConstantPath.Construct (end.position, searchLength, OnPathComplete);

mySeeker.StartPath (constPath);

but I am getting a path failed message

Path Failed : Computation Time 0.000 ms Searched Nodes 0
Error:
Path Number 1

With the error

NullReferenceException: Object reference not set to an instance of an object
ConstantAIPath.UpdatePath () (at Assets/ConstantAIPath.cs:114)
Pathfinding.TargetMover.UpdateTargetPosition () (at Assets/AstarPathfindingProject/ExampleScenes/ExampleScripts/TargetMover.cs:52)
Pathfinding.TargetMover.OnGUI () (at Assets/AstarPathfindingProject/ExampleScenes/ExampleScripts/TargetMover.cs:32)

Hi

You still need to pass a callback to the seeker, just not to the ConstantPath.

ConstantPath constPath = ConstantPath.Construct (end.position, searchLength, null); mySeeker.StartPath (constPath, OnPathComplete);

The NullReferenceException that you got came from your own code, so I have no idea what triggered that since I do not have your script.