List of tags in inspector?

Is there any way to return a list of all existing tags so that one could declare a public variable that would show a popup list of all existing tags in the inspector for a script? Something like the way I can declare:

public var theMask : LayerMask;

but for tags?

You can use EditorGUI.TagField for the editor, but I suppose you mean in-game. I do not know about that. A dirty way would be an object with an array woth all the tags, and you'd have to update it when you add a tag, but it kind of sucks ...

I'm also looking for a solution for this. To be clear and if I understand the question correctly, this is not during run-time, it's for setting a value in the inspector before run-time. For example in my case, I want to make a trigger zone that triggers only if objects with a specific tag go through. Instead of writing the name of the tag in a public String variable, I want to select one of the available tags from a dropdown menu in the inspector. Is this possible? Thank you!

1 Answer

1

There is GameObject.tag, so it depends on what you’re doing. To get all tags in the scene, you’d have to iterate through all objects and collect them as you go. I suppose you could iterate through LayerMask.LayerToName and dig them out of there, but it looks like it does not include the ‘canned’ tags like ‘MainCamera’