Reduce the number of times the path is recalculated

Hey there,

I am trying to reduce the performance impact of the navigation api. My idea is to recaulcate the path only when is actually needed and not every x seconds when walking around.

Do you think this is achievable?

The current obstacles / open points are:
Does RVO avoidance system requires the path to be recalculated or is just pushed on the side?
In the RichAI we have the recalculate the path automatically set on never but during play when the workers walks I can see that is switched to every x seconds. Can this be disabled?

Thanks!

Hi

That should never happen unless some other script sets it to that.
If you are setting the legacy property ai.canSearch then that could have this effect. See the warning associated with that property for more info.

If you use the Dynamic path recalculation mode it will be quite conservative about how often to recalculate the path. But if you want full control you can set path recalculation to Never and only call ai.SearchPath() when you want to update the path.

Hey there,

thanks for the reply!

We are using the Behavior Designer from Opsive that has an integrated API with your pathfinding API. (this one). Every tick (for us is around 0.2f seconds if a character is moving then it set the destination again using the following snippet.

protected override bool SetDestination(Vector3 target)
        {
            agent.canSearch = true;
            agent.canMove = true;
            agent.destination = target;
            agent.SearchPath();
            return true;
        }

Are you saying I should override the default behavior and remove canSearch = true? I don’t see a warning associated with the property (we are using the latest beta in the Rider IDEE).

Thanks,
Paolo

Hi

Yes, I’d recommend removing canSearch = true. That triggers some compatibility code which sets the path recalculation mode to EveryNSeconds.

1 Like

Hey again,

thanks for letting me know! I’ll remove it.