4.1.1 IAstarAI.destination

Hi,

When using 4.1.1b IAstarAI.destination, such as this

IAstarAI.destination = endVector;

It begins to calculate a path correct? How can I know when it has finished pathing?

With seeker, I could do this: seeker.StartPath(startVector, endVector, OnPathComplete); , to get OnPathComplete.

Can I still call a method from the seeker to check?

complete = seeker.IsDone();

Setting the destination will by itself not issue a path request (the agent may do so later automatically though if it is configured to recalculate its path regularly).

You can use the ai.SearchPath method for that. You can check if it is currently calculating a path using ai.pathPending (same name as is used for Unity’s NavmeshAgent).

 IEnumerator Start() {
     ai.destination = blah;
     ai.SearchPath();
     while(ai.pathPending) yield return null;
     // Agent is now following the new path
     while(!ai.targetReached) yield return null;
     // Agent has now reached the destination
}

You can also use seeker.IsDone. It will be the same as pathPending except for one special case. If the AI was traversing an off-mesh link when you called SearchPath, it will not issue a path request until it has finished traversing the link. The pathPending property will return true during this time however the seeker will not have received a path request yet, so it will indicate that the path is already complete.

1 Like

btw. Isn’t it better to set the ‘target’ field on the AI instead of calling StartPath once? That way it will manage to avoid obstacles if any should be placed while it is traversing the path.

You mentioned its generally better to set a target to IAstarAI , instead of calling seeker.startpath();

What if I want to call a flee path or similar, can that be done through a IAstarAI call? Or do I still need to use the seeker to call any constructed paths?

Currently this is not in the beta, but I plan to add a SetPath method.
The idea is that you would disable automatic path recalculations (canSearch = false) and then be able to control pathfinding queries yourself.

You can call the ai.OnPathComplete method (not exposed in the IAstarAI interface however) which does pretty much the same thing as the future SetPath method would do.

Potentially I will design it so that the SearchPath method takes an optional path instance instead.

1 Like

Is there a way to return the path from IAstarAI?

(I am setting the destination from another script (playmaker is very modular as a state machine). So I need something like.

State 1

 ai.destination = blah;

State 2

IEnumerator Start() {
     ai.SearchPath();
path = ai.getpath()
     while(ai.pathPending) yield return null;
     // Draw line along path in game view
     while(!ai.targetReached) yield return null;
     // Disable Line

I found I need to ai.SearchPath() again, in state 2, because the AI is always refreshing the path.

Maybe I need suspend canSearch during state 2.

  1. CanSearch = false
  2. SearchPath()
  3. Do line drawing
  4. CanSearch = true

If it was all done in one state/script, it would be much easier, but it then it is not like “lego blocks” of playmaker.

Follow up on this too.

Right now that is not possible. You can always get the last calculated path from the Seeker component though.

1 Like