- Home /
Question by
MiniFish · Sep 08, 2016 at 09:58 AM ·
custom inspector
Custom inspector how to make nested List play nice
nested list variable in the script :
public List<List<Mission>> mMissionList = new List<List<Mission>>();
when i try to do this
SerializedProperty _stageList = mSrlObj.FindProperty("mMissionList");
Debug.Log(_stageList); // returns null
but if i change the variable to
public List<Mission> mMissionList = new List<Mission>();
result
SerializedProperty _stageList = mSrlObj.FindProperty("mMissionList");
Debug.Log(_stageList); // returns SerializedProperty
the mMissionList is tagged with a [SerializeField], and the Mission class is tagged with [System.Serializable], so i'm not sure why a nested list would cause the inspector script to go nuts. i have a feeling i'm missing something but i can't quite make out what is it.
any guide is much appreciated
Comment
Best Answer
Answer by MiniFish · Sep 09, 2016 at 11:31 AM
turns out it was because unity cannot serialize nested lists. you'd need a wrapper class to do something similar. i got my hint from this question.
in my case, it was something like this,
[System.Serializable]
public class WrapperClass
{
[SerializeField]
public List<MyClass> mMyClassList;
}
making a list of the wrapper that contains the list
List<WrapperClass> mNestedList;
using it
MyClass tempClass = mNestedList[i].mMyClassList[j];
Your answer