Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by dysonarama1 · Jun 20, 2020 at 10:10 AM · scriptableobjectloadingsavingcustom editor

Saving ScriptableObjects in EditorWindow

Hi all,

I'm having an issue with saving scriptable objects in either editor window or a scriptable object. Currently, I have scriptable object nodes/windows that are being inherited from a base node:

 [System.Serializable]
     public class SC_BehaviourTree_BaseBehaviourNode : ScriptableObject
     {
         [HideInInspector]
         public Rect windowRect;
         [HideInInspector]
         public string windowTitle;
         [HideInInspector]
         public List<SC_BehaviourTree_BaseBehaviourNode> Nodes = new List<SC_BehaviourTree_BaseBehaviourNode>();
         [HideInInspector]
         public bool drawConnectingLine = false;
         public float windowRectHeight = 30;
         public float collapsedRectHeight = 60;
         [HideInInspector]
         public SC_BehaviourTree_BaseBehaviourNode StartingNode;
         [HideInInspector]
         public SC_BehaviourTree_BaseBehaviourNode EndingNode;
         public bool collapse = false;
         public bool originNode = false;
         [HideInInspector]
         public Vector2 startPosOffset;

Which is then being saved by the windows editor to another scriptable object.

 void SetNodesDirty()
     {
         EditorUtility.SetDirty(saveObject);
         foreach(SC_BehaviourTree_BaseBehaviourNode Node in saveObject.savedWindowList)
         {
             EditorUtility.SetDirty(Node);
             if (Node.StartingNode != null)
             {
                 EditorUtility.SetDirty(Node.StartingNode);
             }
 
             if (Node.EndingNode != null)
             {
                 EditorUtility.SetDirty(Node.EndingNode);
             }
 
             if (Node.Nodes.Count > 0)
             {
                 foreach (SC_BehaviourTree_BaseBehaviourNode ChildNodes in Node.Nodes)
                 {
                     EditorUtility.SetDirty(ChildNodes);
                 }
             }
         }
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
     }

     void OnDisable()
     {
         SetStartOffset();
         saveObject.savedWindowList = windows;
     }

     void OnEnable()
     {
         saveObject = Resources.Load<SC_BehaviourTree_LoadSave>("Behaviour Tree/Behaviour Tree Save and Load");
         Debug.Log(saveObject.savedWindowList);

         for (int i = 0; i < saveObject.savedWindowList.Count; i++)
         {
             if (saveObject.savedWindowList[i] != null)
             {
                 windows[i] = saveObject.savedWindowList[i];
             }
         }
         Debug.Log(windows.Count + " Behaviour Tree Windows");
         FindOriginNode();
         SetStartPosition();
     }




 [CreateAssetMenu(menuName = "Behaviour Tree / Save File")]
 [System.Serializable]
 public class SC_BehaviourTree_LoadSave: ScriptableObject
 {
     [HideInInspector]
     public List<SC_BehaviourTree_BaseBehaviourNode> savedWindowList = new List<SC_BehaviourTree_BaseBehaviourNode>();
 }

So effectively, what I need to be able to do is save the list of behavior nodes from the behavior tree editor and then reload them and their current variables on enable.

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

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 20, 2020 at 12:12 PM

Uhm, have you actually stored those scriptable objects in any asset file? If not It could only be saved inside the currently loaded scene. But things saved inside a scene can not be referenced by an asset. Only assets can be referenced by other assets. So when you create your scriptable objects you either have to use AssetDatabase.CreateAsset to create a standalone asset or use AssetDatabase.AddObjectToAsset to add the asset to an existing asset file.

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

209 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 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

How to Serialize or Save a List of GameObjects 1 Answer

.data serialize and deserialize work in editor but not in build 1 Answer

ScriptableObject not Serializing? 0 Answers

EditorGUILayout.ObjectField on a ScriptableObject's inspector doesn't update properly 0 Answers

Loading and Saving High Score 1 Answer


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