I have search and It seams impossible, Really?
No solution for this? I need about 3000 tags as a number sequence and I am lazy.
Thanks in advance
I have search and It seams impossible, Really?
No solution for this? I need about 3000 tags as a number sequence and I am lazy.
Thanks in advance
Found this with a quick search.
I’m really curious - what do you want to achieve with 3000 tags?
At first glance it sounds that it might be a workaround for something else. I’m having troubles thinking of a use case that wouldn’t benefit from classifying objects by something else, especially since as you said it’s a number sequence.
wow, I have seen that page but have not look the bottom answers. Thanks. Will post if find a working solution.
well it is a construction game and every obj have a unique ID por saving purposes. I could be using a script with a name string but that would mean more components working in the scene and slower saving.
How does that work for loading, though?
It might be my ignorance in tags usage, but I haven’t seen a way to instantiate an object based on a tag. Only thing that comes to mind is using an intermediary dictionary/lookup/factory, but at this point it’s back into more standard techniques, so might as well not bother with tags at that point.
Also, if you update the project, how do you make sure that each template gets the same ID? The whole system is also a one-off, as reusing it in the next project would be really prone to error I think.
Here is a topic for an rpg inventory, ideas presented there by @TonyLi (even if the topic itself is a little old, it’s good info as usual from him) could be easily translated to your use case. Saving objects is saving objects, no matter what they are. Somehow I find using Tags for individual objects disturbing and easily breakable, not to speak of using numeric ID’s as strings.
It’s your project in the end, but that kind of tag usage makes me shiver a little bit.
I doubt it unity will take 3000 tags. I suggest rolling your own solution. Tags weren’t really designed to be used this way.
What are you trying to do? We might be able to suggest a better solution.
It shouldn’t have a significant impact. Just keep it simple. Alternately, you don’t have to put anything on the object itself. If it is a construction game, where all the objects are placed by the user, just keep track of them in a list or array. You are going to need that list anyway, it is more efficient just to maintain that list. Also, you could use the name of the object as an identifier, make the name the id. As said, that really isn’t the use for tags.
Yes the solution of Leslie-Young really worked EDIT: Actually yoyo make it and use Leslie code.
Thx
public static void AddTag(string tag)
{
UnityEngine.Object[] asset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset");
if ((asset != null) && (asset.Length > 0))
{
SerializedObject so = new SerializedObject(asset[0]);
SerializedProperty tags = so.FindProperty("tags");
for (int i = 0; i < tags.arraySize; ++i)
{
if (tags.GetArrayElementAtIndex(i).stringValue == tag)
{
return; // Tag already present, nothing to do.
}
}
tags.InsertArrayElementAtIndex(0);
tags.GetArrayElementAtIndex(0).stringValue = tag;
so.ApplyModifiedProperties();
so.Update();
}
}
Work in run time and editor by the way, but is really slow to make in runtime a lot of tags
Well it is working great with 200 tags will test if something go wrong with more. Thx
Edit: Yes with 2000 work’s great ( about 10min to create ). But I do not compare tags. I use parse to transform the string to int and save a array of int’s, only use the tag’s to save and load.
You can speed it up a lot.
Those changes will make it process in O(n) time, rather then O(n^2) time. Or whatever the notation is, just trust me, it will be faster.
True, I just copy and paste do not even looked at the script
but really it is just a one time job. Lazy to add manually. Probably would take less time but …
Thx