Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Reizo · Oct 13, 2017 at 09:17 PM · editor-scriptingassetsscriptableobjectcustom editor

ScriptableObjects inside another ScriptableObject not saving changes in Custom Editor Window

Up until, 5.5, this was working fine, but now (2017.1) the changes I make to the cards (which are ScriptableObjects stored in a list inside a Deck, another ScriptableObject) are lost on play/restart. What am I missing?

Basically, I load the Deck asset, from which I get a reference to the list of Cards, which I modify and then use EditorUtility.SetDirty to save the same deck asset. The problem is that all modifications to the Cards contained in the list inside the Deck asset are lost on play/restart.

 public class CardManager : EditorWindow
     {
         #region Variables/References
         public ManagerDeck deck;
         Vector2 scrollPos;
         List<Card> activeList = new List<Card>();
         public List<Card> popupList = new List<Card>();
         #endregion
     
         [MenuItem("Window/Card Manager %#i")]
         static void Init()
         {
             GetWindow(typeof(CardManager));
         }
     
         void OnEnable()
         {
             if (EditorPrefs.HasKey("ObjectPath"))
             {
                 string objectPath = EditorPrefs.GetString("ObjectPath");
                 deck = AssetDatabase.LoadAssetAtPath(objectPath, typeof(ManagerDeck)) as ManagerDeck;
             }
     
             activeList = new List<Card>(deck.CardList);
         }
     
         Rect buttonRect;
     
         void OnGUI()
         {
             GUILayout.BeginHorizontal();
             GUILayout.Label("Card Manager", EditorStyles.boldLabel);
             if (deck != null)
             {
                 if (GUILayout.Button("Show Deck"))
                 {
                     EditorUtility.FocusProjectWindow();
                     Selection.activeObject = deck;
                 }
             }
     
             if (GUILayout.Button("Open Deck")) { OpenDeck(); }
     
             if (GUILayout.Button("Reset Deck")) { ResetDeck(); }
     
             GUILayout.EndHorizontal();
     
             if (deck == null)
             {
                 GUILayout.BeginHorizontal();
                 GUILayout.Space(10);
                 if (GUILayout.Button("Open Existing Deck", GUILayout.ExpandWidth(false)))
                 {
                     OpenDeck();
                 }
                 GUILayout.EndHorizontal();
             }
     
             GUILayout.Space(20);
     
             if (deck != null)
             {
                 scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);
     
                 if (deck.CardList == null)
                     Debug.Log("wtf");
     
                 if (deck.CardList.Count > 0)
                 {
     
                     #region CardDisplay
                     foreach (Card card in activeList)
                     {
                         GUILayout.BeginHorizontal();
                         card.Card_Name = EditorGUILayout.TextField(card.Card_Name as string, GUILayout.Width(Screen.width / 12f));
                         card.Class = (CardClass)EditorGUILayout.EnumPopup(card.Class, GUILayout.Width(Screen.width / 12f));
                         card.Rarity = (CardRarity)EditorGUILayout.EnumPopup(card.Rarity, GUILayout.Width(Screen.width / 12f));
                         
     
                         GUILayout.EndHorizontal();
                         GUILayout.Space(5);
                     }
                     #endregion
     
                     if (GUILayout.Button("Add Card"))
                     {
                         AddCard();
                     }
     
                 }
                 
                 else
                 {
                     GUILayout.Label("This Deck is Empty.");
     
                     if (GUILayout.Button("Add Card"))
                     {
                         AddCard();
                     }
                 }
     
                 EditorGUILayout.EndScrollView();
             }
     
             if (GUI.changed)
             {
                 EditorUtility.SetDirty(deck);
                 AssetDatabase.SaveAssets();
                 AssetDatabase.Refresh();
             }
         }
     
         void OpenDeck()
         {
             string absPath = EditorUtility.OpenFilePanel("Select Deck", "", "");
             if (absPath.StartsWith(Application.dataPath))
             {
                 string relPath = absPath.Substring(Application.dataPath.Length - "Assets".Length);
                 deck = AssetDatabase.LoadAssetAtPath(relPath, typeof(ManagerDeck)) as ManagerDeck;
                 if (deck.CardList == null)
                     deck.CardList = new List<Card>();
                 if (deck)
                 {
                     EditorPrefs.SetString("ObjectPath", relPath);
                 }
             }
         }
     
         void ResetDeck()
         {
             activeList.Clear();
             activeList = new List<Card>(deck.CardList);
     
             if (deck.CardList.Count > 0)
             {
                 SortRelative(CardProperty.ID, activeList);
                 buttonProp = CardProperty.ID;
             }
         }
     
         void AddCard()
         {
             Card newCard = CreateCard.Create();
             newCard.Card_Name = "New Card";
             deck.CardList.Add(newCard);
             ResetDeck();
         }
     
         void DeleteCard(int index)
         {
             deck.CardList.RemoveAt(index);
         }
 }



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

0 Replies

· Add your reply
  • Sort: 

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

127 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

Related Questions

ScriptableObject not Serializing? 0 Answers

How can I get a sub asset? 1 Answer

ScriptableObject not saving to Asset properly 0 Answers

Can't create custom propertydrawer for ScriptableObject 0 Answers

How do you assign the value of a ScriptableObject (from asset) to a component variable? 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