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 /
avatar image
1
Question by LEGEND383 · Dec 18, 2013 at 03:42 PM · scriptableobjectcustom-inspector

Custom inspector for scriptable object resets object

I have a scriptable object that holds a list of objects, and I have a custom inspector for it. When I select the object in the project view it shows the custom inspector however when I make any changes to the custom editor (even just adding an empty line somewhere and saving) it resets the object to default instead of just changing the controls in the inspector.

Here's the inspector code:

 [CustomEditor(typeof(NonBranchingConversation))]
 public class NonBranchingConversationEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         NonBranchingConversation t = target as NonBranchingConversation;
 
         GUILayout.Label("Node Count: " + t.dialogueNodes.Count);
 
         if (GUILayout.Button("Add New Node"))
             t.dialogueNodes.Add(new NonBranchingDialogueNode());
 
         for (int i = 0; i < t.dialogueNodes.Count; i++)
         {
             GUILayout.Label("Node " + (i+1));
 
             t.dialogueNodes[i].text = EditorGUILayout.TextField("Text", t.dialogueNodes[i].text);
             
             Seperator();
         }
 
         EditorUtility.SetDirty(t);
     }
 
     void Seperator()
     {
         GUILayout.Label("-----------------------------------");
     }
 }

And here's the scriptable object:

 public class NonBranchingConversation : ScriptableObject
 {
     public List<NonBranchingDialogueNode> dialogueNodes = new List<NonBranchingDialogueNode>();
 }

If anyone can help with this it would be greatly appreciated.

EDIT: After a bit more goggling, I found something that said to nest one of the classes within the other, but after trying both of mine nested within each other it still doesn't work. Any other suggestions?

Comment
Add comment · Show 2
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 PAEvenson · Dec 18, 2013 at 05:52 PM 0
Share

Try marking both your NonBranchingConversation and NonBranchingDialogueNode as Serializable. Like so:

 [System.Serializable]
 public class NonBranchingConversation : ScriptableObject
 {
     public List<NonBranchingDialogueNode> dialogueNodes = new List<NonBranchingDialogueNode>();
 }
avatar image LEGEND383 · Dec 18, 2013 at 08:47 PM 0
Share

Thanks for the suggestion, but that didn't change anything

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Utamaru · Aug 07, 2014 at 08:42 AM

Maybe its too late, but use this line of the code, after you changed something in your object:

 EditorUtility.SetDirty(target);
 




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
avatar image
0

Answer by LeftyRighty · Jun 04, 2015 at 12:01 PM

just in case someone else comes across this problem in the future, where by changing the editor script code removes the existing items within the scriptable object.

PAEveson was correct the fix is adding [System.Serializable], but you need to add it to the class(es) the scriptable object is storing, not the scriptable object script itself.

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

20 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

Related Questions

Deep Copy of ScriptableObject 1 Answer

Custom Inspector for ScriptableObject 1 Answer

How much bigger are ScriptableObjects compared to normal classes? 0 Answers

ScriptableObject with Custom Editor resetting data in inspector 1 Answer

Implementing a 2D array as a field on a ScriptableObject? 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