Here's my situation. I'm coding scripts for a turn-based game that has an initiative system. Sometimes I need all of the planes to go first, sometimes the ground units, sometimes all the enemies, etc. The FindObjectsWithTag has such good functionality, but tagging an object based on its vehicle type means I can't tag it "player" or "enemy" (which makes things harder in other areas). Is there any way to have more than one tag so that I can iterate through my objects easily? Or is there another strategy in Unity that will get me what I want (simply iterating through planes.Move() after defining "planes" with FindObjectsWithTag is sooo convenient...).
i have a strange solution for you, check here:-
it's a script that allows you to put in Multiple tags on an object...
Angad do you still have that script, the website is tits up. Can you post it here for records?
dead link. Please remove the answer or reupload.
I was looking for a way to do this multi-tag thing as well and happened across the correct URL.
Scroll down to where it says "Unity script that allows multiple tags".
I have yet to try it. Looks pretty basic though.
Answer by andrew
Jul 06, 2010 at 11:45 PM
It is not currently possible, but i use a work-around.
On gameObjects that i need more than one tag on, i add an empty game objects as a child for each tag i need, and give each of these separate tags.. Then you can still search for tags using FindGameObjectsWithTag then just reference the parent object.. as an example in C#
sensedObjects = GameObject.FindGameObjectsWithTag(theTag);
foreach (GameObject foundOne in sensedObjects)
GameObject objectMain = foundOne.transform.parent.gameObject;
That's a really good idea! I'll give it a shot. Thanks!
Brilliant! :D That will help me a lot! :D
awesome idea dude...i'll implement this...
Answer by CodinRonin
Feb 06, 2014 at 08:12 PM
When i want to multi-tag something i create Acronyms for the tags
Ally = All
Minion = Min
Champion = Chm
So when i want for some object to have multiple tags i tag it with a string containing several of them.
ex : "EnChm" (for Enemy Champion) contains "Ch" , and i get by with doing the regular checks :
I like this better. Seems like it will have way better performance... although there should be a best practice on this kind of object tagging and search.
I would even put a tag separator character between tags just for clearance. Also I would avoid using acronyms for better readability.
HAHA good idea! I liked it
If you had a lot of tags, this would begin to get really difficult to manage since you have to input new tags manually in the editor.
Answer by NeilMeredith
Dec 09, 2013 at 10:25 AM
I created a simple asset called Tag Frenzy that allows you use multiple tags in Unity. It is (in my opinion) as easy to use as the built in tag system. You can see it in action here. I'd encourage you to check it out if you don't want to manually add child gameobjects like in the solution above.
Answer by Wumpee
Jan 16, 2015 at 04:47 AM
Or you could use FindObjectsOfType instead
var planes = FindObjectsOfType<Plane>();
I love this in concept, but according to Unity docs FindObjectsOfType is very slow...
Answer by basimhassan
Feb 13 at 08:24 AM
A GameObject has onlyOne tag It cannot contain more than one tag. There r many different ways to find that tag. e.g compare tag. findgameobject with tag etc
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
21 People are following this question.
HELP Find gameObject With tag in another array
Is FindGameObjectWithTag() too heavy on resources for 50 objects?
Is it possible to create a tag programmatically?
How to find one object in specific layer?
Replace variable with new game object after it is made null - not working