In my game, I have some small objects which are not covering any particular node. I just want to remove connections without effecting any node.
Is there any way to do this?
Yes, you can do that.
For non-grid nodes, you can remove or add connections of a single node by calling the RemoveConnection method. Note however that this will only remove the connection in one direction, you will need to call RemoveConnection on the node it was connected to as well to remove the connection in both directions.
For performance, grid connections are stored separately in a bitfield (so it can use only 1 byte of memory instead of approximately 80 bytes). Those connections are currently not modified by calling RemoveConnection, but instead you will have to call the SetConectionInternal method.
See
- http://arongranberg.com/astar/docs/class_pathfinding_1_1_point_node.php#ab6f4676ffe5c6b80a67623d315ab6232
- http://arongranberg.com/astar/docs/class_pathfinding_1_1_grid_node.php#aa994f3b2c50565b86e61859797888dd0
See also this page: http://arongranberg.com/astar/docs/graph-updates.php
How to remove grid connection for a LevelGridNode? There is no SetConnectionInternal method available.
Ah, I found it, but it looks a bit off.
For GridNode we can use:
gridNode.SetConnectionInternal(i, false);
But for the LevelGridNode we can:
levelGridNode.SetConnectionValue(i, LevelGridNode.NoConnection);
Isn’t a little bit weird since both classes inherit from GridNodeBase? Why having 2 separate implementations that actually do the same? Is there a reason for this?