- Home /
Populating a list in the editor
I am trying to make a list that can be worked with in the editor. Every time a new element is added, it should automatically be filled with an object that holds a series of variables with their default values. Right now, i can change the size of the list, but the elements are empty. Thanks in advance for any help. Let me know if you need a code example and i will try and figure out how you do that here!
I feel this is a really simple problem, but i am stumped and cannot find anything online. Anyone able to point me to an example or an explanation?
Answer by whydoidoit · Sep 10, 2012 at 03:15 AM
Make a [Serializable] class that contains your variables and in the class definition set the default values. Then make a public array or list of the class and new items will be initialized for you.
Thanks for the help, but i am still having a little trouble. I have added the [System.Serializable] just above the class that contains the information i wish to hold in my list. The other script file that creates the list looks likes this - public List animationSets = new List(); But when i add a new element it is still co$$anonymous$$g up empty. Specifically the editor looks like this - "Element 0 None (Animation Framesets)". So i guess it knows it is supposed to hold instances of the AnimationFramesets class, but i needs a line where i tell it to create one for each new added element. Tried numerous solutions but none seem to work.
Answer by douglassophies · Sep 14, 2012 at 07:50 AM
I finally worked out the answer. The class i wanted to serialize was extending from MonoBehaviour. I got rid of that and it worked fine.
Oh sorry - that is what I was suggesting - I clearly didn't make a good job of explaining it though!
You gave me a keyword with [Serializable] which enabled me to search for it myself so I still appreciate the help!