Wild… Yeah, I was massively confused by when tags were supposed to be used as indices, and when they were supposed to be used as a bitmask. I really thought that tags-to-nodes were many-to-one, and were used entirely as their bitshifted values (not the 0-31 index).
Please forgive me as I venture deep into feature request territory
For example, if I had a bunch of tags stored in a Tags class:
public static class Tags {
public static readonly uint Dirt = 1 << 0;
public static readonly uint Wood = 1 << 3;
public static readonly uint Treasure = 1 << 9;
public static readonly uint OnFire = 1 << 12;
// ... etc ...
}
With this setup, none of the pathfinding interfaces would use indices at all - they’d all communicate with bitmasks. Both Dirt and Wood could have Treasure on it, but only Wood could be on fire. The Treasure and OnFire tags would be a target for GetNearest()
or PathUtilities.BFS()
, while Dirt and Wood would be for traversability. Imagine upgrading a dirt tile to wood, but it’s right next to lava so it catches on fire:
GraphUpdateObject guo = new GraphUpdateObject() {
modifyTag = true,
removeTags = Tags.Dirt, // (1 << 0)
addTags = Tags.Wood | Tags.OnFire, // ( 1 << 3 | 1 << 12)
};
guo.Apply(node);
Something like this would be particularly useful to me right now, as I have multiple terrain types (sand, dirt, grass) and multiple resource types (wheat, wood, stone)… but every resource can potentially exist on any terrain type. The first set of tags tells my agents what they can walk on, while the second set tell them where they should go (using GetNearest()
+ NNConstraint
and/or PathUtilities.BFS()
+ tagMask
.
I’m not actually sure how something like PathUtilities.BFS()
is useful right now… I’m trying to use it to find the nearest node in a given Area with a certain resource type on it: PathUtilities.BFS(myNode, 15, (1 << TreeTag))
… but this will immediately fail because the ground the agent is standing on isn’t a Tree, so the root node is eliminated and there’s nothing left to do. But if I give it (1 << GroundTag) | (1 << TreeTag )
it’ll return everything inside the radius whether or not it has a tree on it…
Anyway, knowing that nodes and tags have a 1-to-1 relationship, and that getters/setters are indices while masks are bitshifted by the index ( 1 << tagIndex
) will get me pretty far… I think I can get that to work?
Thanks as always for your help!