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

Editor script serialization

Discussion in 'Editor & General Support' started by Mike99, Jan 6, 2016.

  1. Mike99

    Mike99

    Joined:
    Dec 11, 2011
    Posts:
    160
    hi,

    I have a nested list I want to serialize from an Editor class.

    I've created a wraper class to store the inner list, and I have a list of this wrapper class in my script.

    The editor seems to work correctly, I can populate my lists of lists but when I change the scene or close Unity, everything is gone.

    Here is my wrapper class :
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [Serializable]
    6. public class LipsyncListWrapper {
    7.  
    8.     public List<string> lipsList;
    9.  
    10.     public LipsyncListWrapper(){
    11.         lipsList = new List<string> ();
    12.     }
    13. }
    which is declared like this in my script :
    Code (CSharp):
    1.  
    2.     [SerializeField]
    3.     public List<LipsyncListWrapper> lipsSetPaths = new List<LipsyncListWrapper>();
    and used like this in my Editor class :
    Code (CSharp):
    1.  
    2. Sprite s = (Sprite)AssetDatabase.LoadAssetAtPath(lipSync.lipsSetPaths [i].lipsList[j], typeof(Sprite));
    3. lipSync.lipsSetPaths [i].lipsList[j] =  AssetDatabase.GetAssetPath((Sprite)EditorGUILayout.ObjectField(s, typeof(Sprite), true));
    any idea why it doesn't save any value ?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    Do you have your own custom editor (inspector) ? for which type exactly ?
     
  3. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,611
    Perhaps you are not marking the object as dirty when changing it, via Undo.RecordObject?
     
  4. Mike99

    Mike99

    Joined:
    Dec 11, 2011
    Posts:
    160
    Undo.RecordObject ?
    Until now, I was using

    Code (CSharp):
    1. EditorUtility.SetDirty (sceneLoader);
    but as it was not working anymore I added :

    Code (CSharp):
    1. UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty ();
    and it solved the problem.

    Which one should I use then ?
     
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,611
    If possible, you should use Undo.RecordObject. Not only will it set the dirty flag correctly, but it will also give you Undo support.