multiple tags per GameObject

It would be very helpful to be able to add multiple tags to a GameObject.
Having this would be very useful since it is a very useful tool to use and it is fairly performant.

There is not a great way to do this or something similar in function at this moment.

Correction. There is actually a trivial and even more-performant and also compiler-safe way to do it.

Create one MonoBehavior for each Tag you want, make it just a blank MonoBehaviour-derived class, such as:

TagAlly
TagGround
TagFoobar
TagDoodle

Drag those onto GameObjects (in scene or prefabs) and then find them en masse with FindObject(s)OfType<T>() or else GetComponent(s)(InParent)(InChildren)<T>();

Wait, is GetComponent more performant than .CompareTag?
I have always seen everyone saying ‘dont use GetComponent on runtime except if it’s needed’. I want to check tags on collision etc.

But even so, it would be very nice if this was already improvemented with multiple tags

I think the assumption was use of FindGameObjectsWithTag, which is often what tags end up getting used for. If you’re doing a CompareTag like in an OnCollisionEnter call, then CompareTag is probably faster than GetComponent. But you might be surprised just how fast GetComponent actually is.

I would like to have a built in additional tagID as an int.

gameObject.compareTagID(5);

I say this assuming comparing int is going to be way faster…and perhaps have possibly of multiple IDs like you can layers, would solve the OP question

I think CompareTag also works similar (assume it would be like an enum), they recently improved the performance a lot, so it’s not really comparing a string anymore :stuck_out_tongue:
How would TagID be able to assign multiple tags btw? I got a list with game objects I need to add some flag or tag to, but not overwrite the existing tag.
I could add a class which i herits from Component and then check for GetComponent

Not really something i had thought through, just throwing idea out there.

I always read here and there not to use compareTag but i have not speed tested it myself. I just assumed it was a string comparison issue based on others complaints.

My only solution right now would be the same as yours, inherit from a common class with your custom tag system or add tag components.

My rough thought of the multiple ids, i was thinking something like a drop down next to the normal tag with the option for an int or multiple ints.

When checking for the tagID i suppose it would have to go through its array of ids to check for a match if there are multiple… But that same logic could be applied to multiple string tags. I think there are public “multiple tag” assets that might do something similar.

It’s something in the back of my mind…but i have compareTag all over my project and its not really been an issue for me yet honestly.

This might be worth taking a look at

https://assetstore.unity.com/packages/tools/utilities/ezpz-multitag-147798