Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed May 21, 2017 at 06:40 PM by PizzaPie for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by PizzaPie · May 21, 2017 at 01:28 AM · c#serializationeditorwindowsave datacustom editor

ScriptableObject created from custom editor lose data on Unity restart

Well title says it all, i am creating a custom Node Editor i am adding my custom node windows and trying to save their info to a ScriptableObject created as asset. After hour of searching i get Unity doesn't like to serialize custom classes so i stripted it out of any and still nothing happens NodeDataContainer class looks like this after the striping... [Serializable] public class NodeDataContainer : ScriptableObject {

     //public List<BaseNode> windows = new List<BaseNode>();
     //[SerializeField]
     //public List<NodeDialogueDataContainer> dialoguesWindows = new List<NodeDialogueDataContainer>();
     //[SerializeField]
     //public List<NodeResponseDataContainer> responseWindows = new List<NodeResponseDataContainer>();
     [SerializeField]
     public string dataBaseName;
     [SerializeField]
     public DialogDataBase dataBaseReference;}

And here is how i am trying to Save to it from the NodeEditor class

 void SaveDrawings()
     {
         SerializedObject so;       //Second try with serializedObject instead
         if (dataBase== null)
             return;
 
         NodeDataContainer nc ;
         ScriptableObjectUtility.CreateAsset<NodeDataContainer>(dataBase.name+".save",out nc);  //creates Asset and returns a reference of it
         so = new SerializedObject(nc);      //creating the SerializedObject?
         nc.dataBaseName = dataBase.name;    
         so.FindProperty("dataBaseName").stringValue = dataBase.name;
         nc.dataBaseReference = dataBase;
         so.FindProperty("dataBaseReference").objectReferenceValue = dataBase;
         /*for(int i = 0; i < windows.Count; i++)
         {
             //nc.windows.Add(windows[i]);
             if (windows[i].GetType() == typeof(DialogueNode))
             {
                 DialogueNode dn = (DialogueNode)windows[i];
                 nc.dialoguesWindows.Add(new NodeDialogueDataContainer(dn.id, dn.dialogueID, dn.windowRect, dn.dialogue));
             }
             else if (windows[i].GetType() == typeof(ResponseNode))         //obsolete
             {
                 ResponseNode rn = (ResponseNode)windows[i];
                 nc.responseWindows.Add(new NodeResponseDataContainer(rn.id, rn.responseID, rn.windowRect, rn.dialogue, rn.dialogueResultID));
             }
         }*/
         so.Update();
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
         Debug.Log("Saved!");
         //UpdateFlags();
     }

Well lets ignore the lists for start (commended out) so I did try to use SerializedObject with FindProperty to make changes, nothing happend, if not use the SerializedObject everything seem to register properly until i restart Unity then the NodeDataContainer Asset is reseted. From SerializedObject.Update() to AssetDatabase.SaveAssets() nothing seem to work and i don't get what am i missing. Also i should note that i tried EditorUtility.SetDirty(nc) which would corrupt the Asset and make it inaccessible, also tried to add inside OnEnable of DataContainer hideFlag = HideFlags.hideanddontsave which would prevent Asset from being created. If you need more info please let me know. Any Insight on whats going wrong or what i am missing would be appreciated.

Note1: What i don't really get is why would Unity save the data of the Asset if i manipulate them from inspector while it won't through script.

Note2: Any insight on how i can save lists with the custom classes too would be great!

Note3:I know i could easily save the data directly on disc avoiding the whole thing of the Asset creation but i really want to figure this out...

Edit: here is how i create the assets if it matters

 public static void CreateAsset<T>(string name, out T asset) where T : ScriptableObject
         {
             string path = "Assets/Editor/NodeEditorSaveFiles";
             asset = ScriptableObject.CreateInstance<T>();
             AssetDatabase.CreateAsset(asset, path + "/" + name + ".asset");
             AssetDatabase.SaveAssets();
             AssetDatabase.Refresh();
             EditorUtility.FocusProjectWindow();
             Selection.activeObject = asset;
         }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
5
Best Answer

Answer by PizzaPie · May 21, 2017 at 04:38 PM

EditorUtility.SetDirty(object.asset) did the trick, did use it but didn't seem to work not sure what changed.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tcstarr · Apr 21, 2018 at 01:13 PM 0
Share

where did you put it?

avatar image PizzaPie tcstarr · Apr 21, 2018 at 02:14 PM 0
Share

Afterwards from wherever you modify your object. If you are using SerializedObjects though it is better to use the Apply$$anonymous$$odifiedProperties()

avatar image urehelonn · Jul 08, 2018 at 06:38 PM 0
Share

omfg man you're great! You made my day! xD link text

avatar image Black_six · Mar 30 at 01:38 PM 0
Share

Thank You, It also solved my problem!

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Solved] Custom editor resets after Play? 3 Answers

Why Does My Saved Data Not Load? 0 Answers

Custom editor, not serializing 0 Answers

Editor Window script getting values from another script 1 Answer

How to save a two-dimensional array, as part of the variable inspector? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges