- Home /
Tagging Alternatives
Hello,
I just want to know if there's popular alternatives to "Tag".
At the moment, I place a script called "Tagger" and place the tags I want as boolean var.
Then instead of Compare Tag, I do .GetCompenant(Tagger).var == true.
For now it seems to be working. It also permit me to use multiple tags on a single object.
Is there better ways to achieve this?
Answer by Herman-Tulleken · Oct 26, 2010 at 05:25 AM
I like your approach too.
What we do is "register" objects explicitly by putting them in easily accessible collections.
In our GlobalManager class, there is a collection for each "tag".
List<Ship> ships;
List<Pausable> pausableObjects;
and registration methods:
Register(Ship ship)
{
ships.add(ship);
}
etc.
Each object register's itself in Start(). The containers are available through static properties of GlobalManager (which, in our case, is a singleton), so when you need all the ships, you simply call GlobalManager.Ships. We use a lot of interfaces, so that objects can be of multiple types.
This method is simple and convenient, although it becomes clunky as the number of Tags increase.
Answer by Jesse Anders · Oct 26, 2010 at 01:17 AM
Support for multiple tags has been requested frequently, I think, but in lieu of that, your solution seems reasonable. I use a similar method, and I think I've seen similar methods suggested in other threads as well. As long as you're aware of any associated costs (acquiring the component and so on), I don't see why there'd be any problem with that approach.