x


Is it possible to have multiple tags (or the like) on one object?

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...).

Thanks!

more ▼

asked Jul 06 '10 at 11:02 PM

The_r0nin gravatar image

The_r0nin
1.4k 9 14 30

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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;
        //use it...
}
more ▼

answered Jul 06 '10 at 11:45 PM

andrew gravatar image

andrew
549 10 12 18

That's a really good idea! I'll give it a shot. Thanks!

Jul 06 '10 at 11:53 PM The_r0nin

Brilliant! :D That will help me a lot! :D

Apr 15 '11 at 03:26 PM FrHaYwOrKs

awesome idea dude...i'll implement this...

Sep 28 '12 at 06:42 AM kgmr333
(comments are locked)
10|3000 characters needed characters left

i have a strange solution for you, check here:-

http://blockmonkey.com/my-work/unity-3d-work/

it's a script that allows you to put in Multiple tags on an object...

more ▼

answered Apr 01 '11 at 12:00 PM

angad singh gravatar image

angad singh
25 5 5 11

Amazing solution i'm going to use this idea and write my own meta-tagging solution, inspired. Thank you.

Nov 16 '11 at 08:10 AM sacredgeometry

Angad do you still have that script, the website is tits up. Can you post it here for records?

Oct 04 '12 at 07:32 PM ZoomDomain

dead link. Please remove the answer or reupload.

Apr 11 at 06:55 PM Dávid Debnár
(comments are locked)
10|3000 characters needed characters left

Is "http://blockmonkey.com/my-work/unity-3d-work/" a dead link?

more ▼

answered Apr 25 '12 at 10:50 PM

solo24601 gravatar image

solo24601
3 4 4 5

Looks like it

May 02 '12 at 12:12 PM Bluntweapon
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5054
x2073
x321
x53

asked: Jul 06 '10 at 11:02 PM

Seen: 5499 times

Last Updated: Apr 11 at 06:55 PM