How do you apply seeker modifiers to ABPath.Construct

I am looking into pre-calculating paths before sending my seeker so i can do some custom checks based on my game’s requirements. But i am getting errors.

My code looks like this:

void PathCallBack(Path p)
{
    seeker.PostProcess(p);
    myPath = p;
    for (int i = 0; i < myPath.vectorPath.Count; i++)
    {
        Debug.Log(myPath.vectorPath[i]);
    }
}
void NewPathCalculate()
{
    ABPath p = ABPath.Construct(transform.position, target,PathCallBack);
    if (PathUtilities.IsPathPossible(p.path)){
        seeker.preProcessPath(p); //error if i include this (not sure what it does?)
        AstarPath.StartPath(p);
     }
     else
     {
         Debug.Log("Path Not Possible!");
     }
}

The pre process line seems to generate this error:
Object reference not set to an instance of an object CharacterHandler.NewPathCalculate

And if i skip that and just have post process in the callback - it doesn’t apply any processing as i still get a raw path rather than a simplified path the seeker would normally take.

Am i using the methods incorrectly?

1 Like

Hi

Seeker.preProcessPath is an event that you can register to for a callback to be called before the path is processed by modifiers. It is not a method that you would call from some other script.

Seeker modifiers are actually all done after the path has been calculated. So you want to call Seeker.PostProcess which I see that you are already doing in your PathCallback method. It is the exact same code that the Seeker uses so you should get the same results.

@aron_granberg

Thanks for the reply, i thought i had it right but for some reason the gizmo’s show a different path to what the character takes.

So i have the above code and i did a gizmos check:

        if(myPath != null)
        {
            Gizmos.color = Color.magenta;
            for(int i=0; i<myPath.vectorPath.Count; i++)
            {
                Vector3 position = new Vector3(myPath.vectorPath[i].x, 0f, myPath.vectorPath[i].z);
                Gizmos.DrawSphere(position, .5f);
            }
        }

In the image below, you can see the path found here and it is very different to the path found when using the normal seeker.StartPath() ( the character movement still uses the seeker.StartPath() ):

Link: http://imgur.com/a/lPWZf

I’m currently assuming the seeker post process is not applying or i am forgetting to apply something extra to get the same result as the seeker.StartPath finds?

Hi

What modifiers are you using?

This is the settings i am using for the character, the code is part of character handler (which inherits RichAI):

Chatacter Script (inherits RichAI): http://imgur.com/St681bW (numbers are set at run time so they are all zero at start)

seeker seems to already be set in my character script - i believe due to RichAI having it set. So it should be applying the correct seeker.

Character Seeker: http://imgur.com/rhyGCYf

Hi

Ah. So none of those scripts are actually modifiers.
The RichAI script does not use modifiers directly, it instead applies a custom funnel algorithm every frame (just to move to the next corner, it never calculates the whole path at once). You can get a similar result if you add a Funnel Modifier to your GameObject.

1 Like

Ah that did the trick thank you! :slight_smile:

Is there a way to make a custom made path to the seeker without the use of Construct(), that i can create manually then send to the seeker for the RichAI to follow? Basically i want to have a path sequence for entering/exiting stuff that doesn’t require path finding whilst still using RichAI for consistency on animation.

1 Like

Hi

You can make RichAI.OnPathComplete public and just call that with your path. I think that should work.
You may want to disable path recalculations on the RichAI component somehow during that time.

Yeah i thought that might be the way to go, though it accepts a type Path which i don’t know how to construct manually.

Current my pre-made paths are just lists of Vector3 positions. Is there a method where i can send a list of Vector3 points and it will return that list as a Path type which i can then send to OnPathComplete? I am a bit confused how to create the path for it.

Hi

The Path type is simply the base class of all paths, you can send in an ABPath or any other type of path.

The RichAI script does not navigate using a list of Vector3s. It uses the list of nodes and then uses the funnel algorithm every frame to figure out where to move towards.

Ah, i looked at custom path seems that takes a start and end but no way to pass a sequence of world positions and have it construct a path of nodes from. I’m assuming theres no method to do that i’d have to work out my own modifications for it?

Hi

You can create a path like this:

 var path = ABPath.Construct(...);
 path.vectorPath = yourListOfPoints;

Which should work in most cases (notably not for the RichAI script because that uses a list of nodes (the .path field) and not a list of Vector3s.

Note that if you want to pass that to a movement script, keep in mind that they use pooling in which case you might want to increment the reference count on the path to make sure it is not pooled while you are still using it (see http://arongranberg.com/astar/docs/pooling.php). Or you can disable pooling completely under the Optimizations tab.