Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
0
Question by zozazu · Mar 18 at 02:14 PM · custom editor

Having a hard time getting custom editor script changes to save

Hello, I have been trying to get a custom editor script to persist changes that I make in the editor but nothing that I have tried has worked so far. I have the following list in a monobehaviour:

     public class SnapPoint : MonoBehaviour
     {
         public List<SnapPointWhiteList> SnapPointWhiteList = new List<SnapPointWhiteList>();
     }


The snappoint class is defined as:

     [Serializable]
     public class SnapPointWhiteList
     {
         public BuildingPieceBehaviour TargetPiece { get; }
         public Dictionary<SnapPoint, bool> AllowedSnapPoints { get; } = new Dictionary<SnapPoint, bool>();
 
         public SnapPointWhiteList(BuildingPieceBehaviour targetPiece)
         {
             TargetPiece = targetPiece;
             foreach (var snapPoint in targetPiece.GetComponentsInChildren<SnapPoint>())
             {
                 AllowedSnapPoints.Add(snapPoint, true);
             }
         }
     }

My custom editor script that I'm using:

  public class SnapPointInspector : Editor
     {
         private SnapPoint Target => (SnapPoint) target;
         private readonly Dictionary<int, bool> _foldouts = new Dictionary<int, bool>();
         private List<SnapPoint> _snapPointNames = new List<SnapPoint>();
 
         public override void OnInspectorGUI()
         {
             serializedObject.Update();
           
             GUILayout.Label("Allowed Snap Points");
           
             for (var i = 0; i < Target.SnapPointWhiteList.Count; i++)
             {
                 _snapPointNames = Target.SnapPointWhiteList[i].AllowedSnapPoints.Keys.ToList();
               
                 SetFoldout(i, EditorGUILayout.Foldout(GetFoldout(i), Target.SnapPointWhiteList[i].TargetPiece.GetBuildingPieceName(), true));
 
                 if (GetFoldout(i))
                 {
                     foreach (var snapPoint in _snapPointNames)
                     {
                         // GUILayout.Label(snapPoint.Key.name, EditorStyles.label, GUILayout.ExpandWidth(true));
                       
                         Target.SnapPointWhiteList[i].AllowedSnapPoints[snapPoint] =
                         GUILayout.Toggle(Target.SnapPointWhiteList[i].AllowedSnapPoints[snapPoint], snapPoint.name);
                     }
                   
                 }
             }
           
             HandleDragAndDrop();
             EditorUtility.SetDirty(target);
             serializedObject.ApplyModifiedProperties();
         }

And where it's getting saved in the HandleDragAndDrop() method:

  Target.SnapPointWhiteList.Add(new SnapPointWhiteList(draggedPiece));
                             EditorUtility.SetDirty(target);

I've also tried the serializedProperty route and had no luck there. When I edit the values in the editor nothing is persisting.

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

178 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

Related Questions

Calling script when completed field in *EDITOR* 1 Answer

[Solved] Custom editor resets after Play? 3 Answers

How to edit array/list property with custom PropertyDrawer? 3 Answers

Popup to choose which child class I want in Custom Editor Inspector 0 Answers

CustomEditor Inheritance Issue 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