- Home /
The question is answered, right answer was accepted
Is it possible to display a List of GameObject List in a Custom Inspector?
Hi. I'm building on a Custom Editor, and got stuck at following List>() .. Is it Possible however to display the List in a Custom Inspector?
my Idea was the Code below.. but what a surprise it doesn't work..
Script:
List<List<GameObjects>> m_GameObjects;
void OnEnable(){
m_GameObjects = new List<List<GameObject>>();
}
Editor:
MyPersonalScript myTarget;
SerializedProperty m_GameObjects;
public void OnEnable()
{
myTarget = (MyPersonalScript)target;
m_GameObjects.serializedObject.FindProperty("m_GameObjects");
}
public override OnInspectorGUI(){
serializedObject.Update();
for(int i = 0; i< m_GameObjects.arraySize;i++){
SerializedProperty m_objects = m_GameObjects.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(m_objects,true);
}
serializedObject.ApplyModifiedProperties();
}
I hope somebody could help me out here!
dan
Answer by Atiyeh123 · Sep 11, 2018 at 05:04 PM
hi,I don't think so Unity's serialization system doesn't do this , you can't show list of list in inspector. You'll need another type to wrap the array and create a list of that wrapper type instead. you can put the inner list in a script or class. [System.Serializable] public struct GOArray {
public List<GameObject> gameObjects;
// optionally some other fields
}
then you have your list :
List<GOArray> list;
thanks for your answer!
well if i put this right in my script, sorry for the noobish and ungoogled question, would i place this right after the monovehaviour{.. section?
It shouldn't really matter where you put it, for the most part.
(Specifically: If you put it inside the $$anonymous$$onoBehavior, then only the code in that monobehavior can access it, so that might be a plus. Unless you intend to use that GOArray in other scripts, in which case, you probably ought to put it outside.)
public class Something : $$anonymous$$onoBehavior {
[System.Serializable]
public struct GOArray {
public List<GameObject> gameObjects;
}
List<GOArray> listOfLists;
}
// Now, to access it from OUTSIDE the Something monobehavior,
// you would have to say <Something.GOArray>
just wondering is it aswell posible making list of list of list that way? if yes how?
Follow this Question
Related Questions
Access another objects property in an editor script 1 Answer
How to change inspector with non-Monobehaviour objects ? 1 Answer
Custom Inspector: Using SeralizedProperty changes the prefab values! 0 Answers
Enum Dropdown in JS Using Custom Editor? 2 Answers
Custom Inspector: Accessing a reference to another MonoBehaviour? 1 Answer