After a day spent trying to figure this out, its just killing me.
I followed your tutorial step by step, everything SHOULD work, but the path is just NEVER returned, nothing ever comes out of seeker.
void _updatePath()
{
seeker.StartPath(transform.position, targetPosition, OnPathComplete);
if (path == null || path.vectorPath == null)
{
Debug.Break();
Debug.LogError("no path returned");
}
currentPathPoint = 1;
timer = 0;
forceRefresh = false;
}
public void MoveToCurrentWaypoint()
{
targetPosition = currentWPN.waypoints[currentWaypoint].transform.position;
_updatePath();
List<Vector3> vPath = path.vectorPath;
Debug.Log(vPath.Count);
if (Vector3.Distance(transform.position, vPath[currentPathPoint]) < currentPathPointDistance)
{
currentPathPoint++;
}
transform.localPosition = Vector3.MoveTowards(transform.localPosition,
vPath[currentPathPoint],
currentSpeed);
RaycastDown();
hitWorldPos = worldMover.transform.InverseTransformPoint(_hit.point);
transform.localPosition = new Vector3(transform.localPosition.x, hitWorldPos.y + raycastYOffset, transform.localPosition.z);
}
public virtual void OnPathComplete(Path p)
{
Debug.Log("Yay, we got a path back. Did it have an error? " + p.error);
path = p as ABPath;
}
i checked everything i tinkered with everything and it just doesnt work AT ALL.
also this
Path Failed : Computation Time 0.00 ms Searched Nodes 0
Error: Couldn’t find close nodes to the start point or the end point]
which is a lie, because everything is properly set up, the graph is there the manager is there, everything should work
public void MoveToCurrentWaypoint()
{
targetPosition = currentWPN.waypoints[currentWaypoint].transform.position;
_updatePath();
Debug.Log(path.vectorPath.Count);
if (Vector3.Distance(transform.position, path.vectorPath[currentPathPoint]) < currentPathPointDistance)
{
currentPathPoint++;
}
transform.localPosition = Vector3.MoveTowards(transform.localPosition,
path.vectorPath[currentPathPoint],
currentSpeed);
RaycastDown();
hitWorldPos = worldMover.transform.InverseTransformPoint(_hit.point);
transform.localPosition = new Vector3(transform.localPosition.x, hitWorldPos.y + raycastYOffset, transform.localPosition.z);
}
Path Completed : Computation Time 3.00 ms Searched Nodes 53 Path Length 8
Path Number 1
but as soon as it gets to
Debug.Log(path.vectorPath.Count);
it suddenly
NullReferenceException: Object reference not set to an instance of an object
NPC.MoveToCurrentWaypoint () (at Assets/code/Ai/NPC/NPC.cs:224)
WHAAAT?!
it computes it but never returnes it just doesnt
or wait im lying it never computes it it was OTHER ai that works that computed it, so here it never even tries to do anything
no callback is ever happening
thanks for help, you could just tell me to look for answer some other place.
delete thread pls and dont answe i dont care also there is no option to delete account, so remove it
I see that MoveToCurrentWaypoint you have _updatePath. That will likely cause the _updatePath method to run quite a lot which means that you will be calling StartPath a lot. When the seeker is already calculating a path, but it receives a new path request, it will cancel the old one and start to calculate the new one, so if you call StartPath often, it might never have time to completely calculate a path request. I suggest that you use check seeker.IsDone before requesting paths to make sure it isn’t already doing something.
Also, the path calculation is not instantaneous, so directly after the seeker.StartPath call, the path will most likely not be calculated, it will be calculated over the next frame(s) (depending on how long it is). So your statement which says Debug.LogError(“no path returned”) will probably always be triggered.
1 Like
void _updatePath()
{
Debug.Log(transform.position );
Debug.Log( targetPosition);
if(!initPath)
{
seeker.StartPath(transform.position, targetPosition, OnPathComplete);
initPath = true;
}
if (seeker.IsDone())
{
seeker.StartPath(transform.position, targetPosition, OnPathComplete);
if (path == null || path.vectorPath == null)
{
Debug.Break();
Debug.LogError("no path returned");
}
currentPathPoint = 1;
timer = 0;
forceRefresh = false;
}
}
public void MoveToCurrentWaypoint()
{
targetPosition = currentWPN.waypoints[currentWaypoint].transform.position;
_updatePath();
if (path != null)
{
Debug.Log(path.vectorPath.Count);
if (Vector3.Distance(transform.position, path.vectorPath[currentPathPoint]) < currentPathPointDistance)
{
currentPathPoint++;
}
transform.localPosition = Vector3.MoveTowards(transform.localPosition,
path.vectorPath[currentPathPoint],
currentSpeed);
RaycastDown();
hitWorldPos = worldMover.transform.InverseTransformPoint(_hit.point);
transform.localPosition = new Vector3(transform.localPosition.x, hitWorldPos.y + raycastYOffset, transform.localPosition.z);
}
}
Love you Aron <3
1 Like
Hi, getting this same issue quite often in my game, tried adding the if(seeker.IsDone()) check to the AIPath script, and my AI still don’t find a successful path very often. Tried playing around with tons of different settings, but can’t for the life of me get them to work reliably on my main scene - the only thing I can think of is that my grid is simply too big? I’ve got them working in my small test scene pretty much 100% of the time, bit stumped.
http://imgur.com/N1Gno9D - Grid settings
http://imgur.com/Kqfd7mH - Settings