Making a node walkable again

Hi,

I’m making a turn-based game, where each unit will move one after the other. I have to handle differently-sized units, and have to be sure units don’t block themselves. After reading the docs, I thought that the simplest approach for me would be:

  • When I place a unit on the map, I make all the nodes it occupies unwalkable (just by setting the walkable variable to false)
  • Just before I compute a path for my unit, I set the same nodes to walkable = true
  • I compute the path
  • Once the path is complete, I set the nodes of the unit unwalkable again.

I’ll then use a custom ITraversable to check for units of different sizes (but not implemented yet, though, so this is not the problem here).

So when I put a unit on the map, I set all its nodes to unwalkable. The problem is that even if I set back its nodes to walkable again before calculating the path, the path will always return a 1 node path, as it the unit was still blocking itself. I even tried to only have a 1x1 unit, and it still behaves like this. The gizmos in the editor show me the nodes are walkable though, as expected.

I tried to call CalculateConnectionsForCellAndNeighbours() every time I change the walkable value, but to no avail. I even tried to delay the call to the path creation, in case the system would need some time to update the walkable states, with no more success. It looks like once a node has been made unwalkable, I won’t be able to make it walkable again for the path finder.

Am I doing something wrong, or is it a limit of the system?

Thank you very much for your help.

Hi

Sorry for the late answer.
Do you do the graph updates in inside a work item (AstarPath.active.AddWorkItem)?
https://arongranberg.com/astar/docs/astarpath.html#AddWorkItem3

However, if you already use a custom ITraversalProvider, it might be much easier to make that keep track of where the units are and make the nodes unwalkable only for all other units, but keep the node walkable for the unit itself. See this page for some more details: Utilities for turn-based games - A* Pathfinding Project

Hi Aron,

Thank you for your reply. I ended up using tags only, making them traversable or not. It worked fine. :slight_smile: (your asset is really amazing, btw!)

One extra question, please: when I update a tag value on a node, do I have to call CalculateConnectionsForCellAndNeighbours() systematically on that node after I change the Tag value?

Thank you!

1 Like

I’m using tags to mark open and closed doors.
Changing the tags when opening/closing a door works (AI does not walk on tags marked as not walkable), and I never call CalculateConnectionsForCellAndNeighbours().

Edit: I’m using a RecastGraph though, so I might be wrong here.

2 Likes

No, connections are not affected by tags.

1 Like

Thank you both for your kind replies!

1 Like