Hi guys
I’m having a relatively small issue, that I for the life of me cannot figure out how to handle.
I want to make an array in which I can allocate stats on various units from the inspector.
That in itself seems relatively straight forward.
To give an example with 1 unit:
Size (1)
Name (string)
Health (int)
Attack (int)
I would however also like to be able to allocate traits like flying, invisible or regenerating to the units, and this is where things get a bit messy.
At this point the inspector looks like this:
Size (1)
Name (string)
Health (int)
Attack (int)
Traits (my script with traits in it)
Size (1)
Element 0
Flying (bool)
Invisible (bool)
Regeneration (script where the regeneration trait is divided into subsections)
Size (3)
Element 0
Regeneration 1 (bool)
Regeneration 2 (bool)
Regeneration 3 (bool)
When it would be a lot less messy and more effective if it looked like this:
Size (1)
Name (string)
Health (int)
Attack (int)
Traits (my script with traits in it)
Flying (bool)
Invisible (bool)
Regeneration (script where the regeneration trait is divided into subsections)
Regeneration 1 (bool)
Regeneration 2 (bool)
Regeneration 3 (bool)
I don’t know if it makes sense to you readers when put up like this, but is there a way to make subsections appear automatically in the size of 1, without showing it in the inspector, so that you get rid of the “size” and the “element 0” section in the inspector?
You can initialize the array to be of size 1 by default, but you’re still going to have the “size” and “element 0” headers because it’s how Unity draws arrays in the inspector. If you wish to get rid of them, you’ll have to write a custom inspector.
In reality, this doesn’t sound like a good use case for arrays to begin with. Why not just be declarative and put the properties you want in the thing you’re customizing?
But even so there are still some of the boolean values that would be nicer to have as a drop-down value in the inspector, so that every unit doesnt have +30 checkboxes open in the inspector, due to irrelevant traits for that unit specific unit.
It’s purely a cosmetic thing while programming though, so maybe it’s just one of those things I should learn to live with
This. Put all your traits in a SciptableObject and then let the unit reference just that. When you need a new one, just make a new SO instance and configure appropriately.