How to update a TraversalProvider's properties

  • A* version: 5.4.6

  • Unity version: 6.1.2f1

    I have an agent that I want to avoid the line of sight of a player and try to navigate behind them. Using a ITraversalProvider seems like the best way to do this (check if the node is in the forward cone of the player and if so, return a higher cost).

    The issue with this approach is it requires the traversal provider to have the up to date position and forward direction of the player. What would be the best way to update them? Or would another approach be recommended?

    Thanks!

Hi

You can keep a reference to it in your script and update the parameters directly there.

For extra safety, you could create a new ITraversalProvider every frame and assign it to the agent. But for this use case, I think you can be a bit unsafe.

Why would you ever need that? The ITraversalProvider is used in separate pathfinding threads, so if you modify it, that might be in the middle of a pathfinding calculation.

Okay, I just didn’t know if there was a better way to go about it that would be faster or create less GC while staying thread safe.

But if not, will just create a new ITraversalProvider every frame or every x frames and assign it to the agent.

1 Like

Is there some way to do this without allocating GC?