- Home /
Automatically increment an integer field in a bunch of prefab gameobjects in the unity editor.
Hello all,
So I have a gameobject called ListOfAllItems and it is a prefab that I want to use to look up and spawn items in the game. It contains all the items in the game as children of itself. Each item has an integer field called "WorldItemId", and there are maybe over a hundred items.
I want to populate the id field automatically in the same order it is in the parent list, so for instance, the list looks like this:
ListOfAllItems:
Cloak, Id: 0
Sword, Id: 1
Potion, Id: 2 ...
And so on. Is there a way to do this via editor scripting or some feature already inside unity? Because otherwise I think I'd need to go to each item and fill in the field myself a hundred or so times. While this is tedious work, I can do it, it's just that automating it will also make it less prone to mistakes in numbering.
Your answer
Follow this Question
Related Questions
How to detect if Prefab was added to the scene in Edit Mode? 1 Answer
Using a custom editor script with a prefab instance causes my variables to reset on Play 3 Answers
How do I make fields in the inspector go bold when prefab value is overridden 4 Answers
Initializing a prefab from script in edit mode without breaking the connection 1 Answer
Initializing 2D array via inspector 3 Answers