Hey There!
I recently installed the latest version of AStar Pathfinding Project. I am using a point graph for my flying spaceships. At one point, all they have to do is to follow the nodes, which are part of a patrol route. But it keeps throwing this error
"The path has an invalid state. Expected created found Returned
“Make sure you are not requesting the same path twice”.
I dont understand what’s happening here. It was working fine on the previous version. Also, has the ability to create a ‘new’ instance of a Path been removed. If so, I think this might be causing the problem for me.
Here is the problematic code:
void Convoy_EnterState()
{if(IsLeader) { RouteNodes = new Transform[Route.childCount]; i = 0; foreach(Transform t in Route) RouteNodes[i++] = t; RouteNodesIndex = 0;
targetReached = false;
// RouteNodesIndex = 0;
currentWaypoint = 0;
// SetPath();
// Debug.DrawLine(tr.position, RouteNodes[0].position,Color.red);
path = GetPath(tr.position, Vector3.zero, OnPathComplete);
// vPath = path.vectorPath;
// pathLength = vPath.Count;
}
else
{
//empty for now
}
}
void SetPath()
{
Debug.Log(“Here?”);
targetReached = false;
RouteNodesIndex = RouteNodesIndex + 1;
currentWaypoint = 0;
if(RouteNodesIndex >= i) { currentState = States.Gaurd; }
path = GetPath(RouteNodes[RouteNodesIndex-1].position, RouteNodes[RouteNodesIndex].position, null);
}
void Convoy_Update()
{if(IsLeader) { Debug.Log("Here?");
// vPath = path.vectorPath;
// pathLength = vPath.Count;
if(path == null) return;
if(currentWaypoint > path.vectorPath.Count) return;
if(currentWaypoint == path.vectorPath.Count && currentWaypoint != 0) { targetReached = true; SetPath(); } Debug.DrawLine(tr.position, path.vectorPath[currentWaypoint],Color.red); if(!targetReached) { targetForPatrol = path.vectorPath[currentWaypoint]; } base.Chase (targetForPatrol);
if(SqrDistanceToTarget < nextWaypointDistance * nextWaypointDistance && !targetReached) currentWaypoint++;
// if(targetForPatrol == PatrolPoints[PatrolPoints.Count-1].position) } else { FollowConvoy(groupLeader.position + groupLeader.TransformDirection(offset)); }
}
Thanks!