AIPath vs. Seeker?

I’m a bit confused on the difference between Seeker and AIPath. Both seem to have OnPathComplete for example?

For example, in order to add Flee logic, I implemented the following suggested code:

public void Flee(Vector3 theFleeSource)
        {
            // Disable the automatic path recalculation
            canSearch = false;

            // Make the AI flee from the enemy.
            // The path will be about 20 world units long (the default cost of moving 1 world unit is 1000).
            var path = FleePath.Construct(position, theFleeSource, 1000 * 20);
            SetPath(path);
        }

I call it from another script with:

// FLEE!!!
GetComponent<AIPath>().Flee(HitFrom);

But, my object stops pathing once it is done fleeing? How do I make it resume using the Seeker component (if I want to)?

What I really want to do is have a state machine that may be seeking, fleeing, randomly moving, or just sitting there. Should I extend the AIPath class to have the various functions or do something else? Struggling with understanding how AIPath, Seeker, and other classes really work together. I there a visual digram somewhere with the logic flow?

Thanks!

Hi

The Seeker component is a helper script to make pathfinding requests easier, it handles path modifiers and similar things. It is not responsible for any movement of the character, that is the movement script’s job (e.g AIPath).

The AIPath script tells sends path requests to the Seeker component which then in turn sends those to the core pathfinding system which calculates them, then the Seeker post processes the paths using modifiers and finally it sends it back to the AIPath component for it to follow.

The AIPath script regularly calculates a path to the point indicated by its destination property if the canSearch property is true. In the code you can see that it disables the automatic path recalculation (canSearch=false), but you can enable that again after some time if you want the agent to move to another point for example.

1 Like

Thanks for the explanation Aron. One question, should I be modifying the AIPath class or the Seeker class to add my own functionality? I’m worried about a new release which will wipe out my code and am not sure of the best practice to follow here?

As mentioned before, I want to make AI that uses behavior trees to determine which paths (if any) to call, when, etc. I was looking at a behavior asset on the asset store that claims to work well with your A* library.

Food for thought… it may be cool if you released upgrades but didn’t touch the things people modify. Maybe in a separate package or something? Free release of AIPath, AIBase, etc, but require a purchase of everything they reference. Something to make it easier to mod your own without releases blowing the work away.

Hi

It depends on what type of behavior you want to add. I have been trying my best to make it possible to not have to modify or extend the AIPath script at all. Instead you could add a new component that uses the various properties and methods of the AIPath class.
You should not modify the Seeker, there is very little there that could useful to change.

In case you really do want to modify the AIPath script and want to make sure all the code works in future versions, I think it should be possible to duplicate the AIBase, AIPath and AIBaseEditor scripts and modify the names of the classes to avoid collisions, and then they should continue to work even if you upgrade the package.
Another very useful thing is to use version control to merge in the changes that I do via upgrades.

1 Like

I see… I’ll remove my code and try to just call AIPath as it’s own thing. Can you give an example of how to add Flee pathing and Random pathing but without adding it to AIPath? Currently I added Flee and Random functions to it but would want to pull those out given your recommendation.

Thanks!

Hi

Just like this:

// Disable the automatic path recalculation
ai.canSearch = false;

// Make the AI flee from the enemy.
// The path will be about 20 world units long (the default cost of moving 1 world unit is 1000).
var path = FleePath.Construct(position, theFleeSource, 1000 * 20);
ai.SetPath(path);

where ai is a reference to the AIPath component (or another movement script).

1 Like

Cool!

Is there a way to poll whether or not the path is complete so that I can take the next action (such as turning search back on)?

Yes, you can do a check like this:

// Make sure the path has been calculated and that we have reached the end of it
if (!ai.pathPending && ai.reachedEndOfPath) {
    // Do stuff
 }
1 Like

Perfect, thanks for the quick replies!