- Home /
Creating tags via code
Is it possible to create tags via a script rather than creating them manually?
basically i have over 20 enemies
adding the tag looks like this
private GameObject[] enemies;
void Start ()
{
enemies = GameObject.FindGameObjectsWithTag ("Enemy");
for ( int i=0; i<enemies.Length; i++ ){
enemies[i].tag = "enemy" + (i+1).ToString() ;
}
}
would be great if i could create tags as and when needed
I doubt that's something best done with tags. Tags are meant to apply to a group of related objects; you wouldn't have a different tag for every single object. Probably you want to set the name ins$$anonymous$$d, which you can do in code.
Answer by Eric5h5 · Feb 12, 2012 at 12:41 AM
Tags can only be created in the editor.
that's what i was afraid of....
looks like i need to get busy with adding all those tags D:
thanks for reply :)
And there's no way to create them via a custom EditorWindow, right? I'm looking into it but can't find a solution.
Answer by Bunny83 · Feb 12, 2012 at 02:40 AM
Tags are usually used to group similar objects or to identify (tag) it as part of that group. If every object should have it's own tag, i don't see why you not just use the name instead of a tag... You know that there's GameObject.Find which can be used to search for the gameobject's name.
The name can be changed to anything you like.
Answer by neosca · Mar 01, 2017 at 07:25 AM
You can also try something like this with a customeditor:
http://answers.unity3d.com/questions/33597/is-it-possible-to-create-a-tag-programmatically.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613064008im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to create a new Tag by script ? 1 Answer
Make rolling ball player spin script 1 Answer
how to find tags 0 Answers
Enabling/Disabling Multiple Tagged objects 1 Answer
Same objects doing the same thing 0 Answers