UpdatePhysics for graph update affects surface of graph on different height

  • A* version: 5.3.3
  • Unity version: 2022.3.60f1

Hi, I’m using a recast graph for pretty dynamic world. By dynamic world I mean that player can change it in any second: remove some blocks, add some blocks, place water and so on.

The problem is the following:

  1. When player places water in the world, I’m changing the tag of the graph for water surface, this tag plays the role of penalty for seekers [Each seeker(NPC) is set up in such a way that the water tag is treated as penalty area, so NPCs avoid water but if they ended up in water they can navigate through it]. So far so good. By the way, I’m not updating physics on this step, just getting nearest graph nodes to water and changing their tags
  2. When player places blocks above water [I do update physics for these blocks, to allow NPC to climb on them] the water surface graph updates with the blocks’ surface graph, meaning that penalty tag for water becomes the same as for blocks [no penalty], and the graph surface of water changes it physics although they are on different heights [graph surface of water and graph surface of blocks]. ← This is the problem

Expected behavior:
Graph surfaces of water and graph surface of blocks that are placed above water are fully decoupled and do not influence each other.

Additional details:
GraphUpdateObject is used for recast graph updates

Hi

When updatePhysics=true, the recast graph will recalculate the whole tile from scratch. This means everything in the tile is affected. It will try to preserve existing penalties and tags, but may not be able to do so in all circumstances.

For a more robust method, I would recommend adding the RecastMeshObj component to the water surface, and changing its settings to mark that surface with a given tag. Then any graph update (or scan) with updatePhysics=true will detect that surface and set the given tag automatically.

Hi, Aron, thank you, it works. Just curious is there any technical limitation that enforces parts of the graph to be only updated physically ignoring other attributes of the graph update object, like penalty, tags? Or because of physics updates the graph nodes change and the previous surface changes as well, so it’s unsafe to apply the same rules for the surface of the graph as it was before?

When a full tile recalculation happens, the triangulation may not stay exactly the same. If it doesn’t, there’s really no good way to preserve previous updates to the graph. This is why a declarative approach (using the RecastMeshObj) is preferred over an imperative approach (GraphUpdateObject setting specific tags/penalties on existing nodes).
So yes, it is very much a technical limitation.