Updating navmesh connection cost at runtime

  • A* version: 5.3.3
  • Unity version: 2022.3.58

Hi,
I’m wondering what the correct/best way is to update a NavMesh graph node’s connection cost at runtime would be?

I have certain sections of my nav that can be toggled to be blocked in one direction only at runtime. Since these points on the nav will not move, I was baking the node/connection lookup at build time, and at runtime I lookup those nodes/connections and update the Connection.cost property.
This worked in the 4.2 beta branch, but after upgrading to the latest 5.3.3 version, updating the connection costs in this way does not seem to take affect (my agents still follow the path as if the cost was the original cost).
Should the agents, the next time they calculate their path, see this new connection cost and take it into account when determining their path? Or is there some other method I need to call before agents will “see” this updated cost?

If I did not care about the directionality of the path, I could set the Node.penalty, and this does seem to still work. The agents see the updated penalty at runtime after I change it and correctly choose a different path that doesnt run through those nodes. But updating the connection costs does not seem to take affect.

This is essentially what I’m doing at runtime

graphNode.connections[i].cost = penaltyCost;

Thanks for the help

ok, I’ve figured out a resolution to my use-case

It looks like I can now specifically define that you cant traverse the connection from one of the directions

connection.shapeEdgeInfo ^= Connection.OutgoingConnection;

I can update this at runtime and the agents take it into account on next repath.

Hi

Please note that if you are doing that, you should also modify the shapeEdgeInfo on the corresponding connection on the connected node, so that it doesn’t think there’s still an incoming connection to that node.

hi, thanks for the response.

Yeah, I’m doing that (clearing out the Incoming on the connected node’s connection as well), and it seems to work perfectly for what I need.

Thanks again