- Home /
Initializing List of generic type via editor - Doesn't work?
Hi!
I want to initialize a List of Gameobjects via Editor. Does this work?
Code:
public List<GameObject> gameObjectList = new List<GameObject>();
The List is shown in the Editor and I can type in the size. I typed in 2. Then i added 2 Prefabs via drag and drop.
But the List is always empty when I try to get some Objects back via: gameObjectList[index]... so there is nothing initialized...
Is there are List Type with which I can collect gameobjects via editor?
Answer by frarees · Apr 07, 2014 at 09:20 AM
Access the list via SerializedObject (e.g. serializedObject.FindProperty ("gameObjectList.Array.data[0]").objectReferenceValue).
Make also sure that changes to your objects are applied and saved to disk hitting Ctrl+S.
Thank you very much. I did a workarround,yet. But I will test your solution as fast as possible!
Another solution would be creating a non-generic class, like discussed here
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Create a null GameObject List using Boo 1 Answer
in-editor cloning of game objects 1 Answer
Using Generic List with serializedProperty Inspector 3 Answers