Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

A List of Lists as a SerializedProperty

Discussion in 'Scripting' started by leifgood, Apr 22, 2019.

  1. leifgood

    leifgood

    Joined:
    Nov 28, 2015
    Posts:
    12
    Im working on a Custom Editor, and for that I need certain properties serialized. My problem is, that one of those properties ist a list of lists and I can not serialize it. Following Example:

    Code (CSharp):
    1. // In my Class
    2. public List<TransitionLine> transitionLine = new List<TransitionLine>();
    3. public List<List<TransitionParameter>> transitionParameterLists = new List<List<TransitionParameter>>();
    4. // In my Custom Editor
    5. SerializedProperty transitionLineProperty = serializedObject.FindProperty("transitionLine");
    6. SerializedProperty transitionParameterListsProperty = serializedObject.FindProperty("transitionParameterLists");

    transitionLineProperty will be the desired property, transitionParameterListsProperty will be null. Making a List of Arrays leads to the same result. TransitionLine and TransitionParameter are both Scriptable Objects.

    Any Ideas on how I can make the latter one work as a serializedProperty as well?
     
    Last edited: Apr 22, 2019
  2. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    You could make a field for every list item, with a length field next to it, in order to change the size.
     
  3. leifgood

    leifgood

    Joined:
    Nov 28, 2015
    Posts:
    12
    If I understand you correctly, this would limit me to a predefined number of lists. For my usecase, I need a variable amount of lists. To add a little background information, transitionLineProperty is used in a ReorderableList, and with every entry I create there, I add a new ReorderableList that uses one of the Lists of transitionParameterListsProperty.