Changing destination and knowing about it


I feel after using this plugin all these years I should’ve known the answer to my question but here goes:
I change destination at every 250ms which my AI thinks. My problem is that since it’s multithreaded it doesn’t know that it’s changed destination until it’ll be checked so my question is: “is there any way to understand that the rest of the variables ( remainingDistance, hasPath, reachedEndOfPath, etc ) are out of date?”

I set RichAI this way:

	m_Agent.destination = TargetAgent.Position;

and then check on an update:

			if( m_Agent != null && m_Agent.hasPath )
				if( m_Agent.remainingDistance <= m_Agent.endReachedDistance || m_Agent.reachedEndOfPath )

but because it’s every 250ms remaining distance stays the same even if I change destination.


hasPath will become true as soon as the path has been calculated.
reachedEndOfPath is tricky, I would discourage using it and use reachedDestination instead, which tries much harder to never be out of date.
remainingDistance will be out of date while a path is being calculated.

Essentially, if you set a destination like:

ai.destination = ...;
ai.SearchPath(); // don't do this every frame

Then you can check

if (ai.pathPending) {
    // Path is still being calculated
} else {
    // Path is up to date

See also IAstarAI - A* Pathfinding Project