A* Pathfinding Project
3.8.2
The A* Pathfinding Project for Unity 3D
|
Tagging nodes and areas is a powerful feature.
It is used to restrict which units can walk on what ground.
Imagine for example that you have some critters, a player and some AIs in your world. Both the AIs and the critters pathfind randomly around in the world but you wouldn't want the critters to enter houses (they make such a mess). Then tagging is a great way to solve it. If you tag all indoor areas with a tag named "Indoors" and make sure no critters can walk on those nodes, that would be it!
Here's a video showing the features of tagging and the GraphUpdateScene component which is a great help for tagging areas.
Tagging is done so that first, you mark some nodes with a tag. Then on the Seeker component there is a setting for "Valid Tags" this setting, which is popup you can set which tags should be traversable by that unit. The first tag (usually named "Basic Ground") is set on all nodes at start. Then when pathfinding, the seeker will set which tags the path should be able to traverse (the ones you set in the editor), and it will try to find a path using that contraint. When searching for the closest node, it will also make sure that a node which has a valid tag set will be chosen.
Below is an image of a Seeker component which can traverse all tags except the restricted area tags.
As said above, the GraphUpdateScene component is a great help when tagging nodes. It has got a setting for "Modify Tags", which sets if it should modify the tags of the nodes in the polygon, and also "Set Tag" which defines which tag to mark the nodes with if "Modify Tags" is set to true. For some help on how to use the GraphUpdateScene component, take a look at the Graph Updates page.
You can debug tags by changing the debug mode to Tags in A* Inspector –> Settings –> Debug –> Path Debug Mode (and make sure Show Graphs is toggled). This will render the graphs so that each tag get's a specific color which allows you to separate them easily.
Tags can also be named for ease of use. In A* Inspector –> Settings –> Tags you can set the names of the tags. These names will then be used in all tag selection fields.