Getting an exception when calling WaitForPath in editor (non-playing)


#1

Hi. I’m trying to call WaitForPath on a MultiTargetPath while in the editor (not in play mode):

// My code
var p = MultiTargetPath.Construct(origin, targets, onPathCompletes, OnPathComplete);
p.pathsForAll = true;
AstarPath.StartPath(p);
AstarPath.WaitForPath(p);

I’m getting the following exception:

 System.NullReferenceException: Object reference not set to an instance of an object
  at AstarPath.WaitForPath (Pathfinding.Path p) [0x00148] in /Users/mikelaurence/projects/lunar-lockdown-2d/Assets/AstarPathfindingProject/Core/AstarPath.cs:2244

This is what’s at AstarPath line 2244:

//Calculate some paths
threadEnumerator.MoveNext();

Any suggestions for how to move forward here?

I’m on v 3.8.12.


#2

Hi

3.x does not have support for using pathfinding outside of play mode.
4.1.x does have that however, you can take a look at the docs for it here: https://arongranberg.com/astar/docs/editormode.html


#3

Great – I upgraded and it works, thanks!