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 tenshiko · Aug 25, 2016 at 02:56 PM · unity 5editorwindowundo

Tracking changes of a Component on the selected GameObject in custom EditorWindow

I am trying to create my own EditorWindow for one of my components called Interactable (see code later).

The edit window will eventually become much more complex, but for now all I have in it is a few boxes and text fields. I want this custom EditorWindow to work much like the Animation window, meaning: it only displays stuff when the selected gameObject has an Interactable component and I mainly want to edit the properties of the Interactable.

THE PROBLEM: So far everything's peachy, except that I can't make the editor register any changes of the Interactable (i.e. the little asterisk does not appear in the main window title and therefore my changes cannot be saved). (My Unity version is 5.3.5 btw)

I must have missed something. How do I make this work? Any help is appreciated!

Here are the relevant classes:

 [Serializable]
 public class InteractionNode
 {
     public string Name { get; set; }
     public Vector2 Position { get; set; }
     public Vector2 Size { get; set; }
     
     public InteractionNode(string name)
     {
         Name = name;
     }
 }
 
 [Serializable]
 public class InteractionGraph
 {
     public List<InteractionNode> Nodes { get; set; }
 
     public InteractionGraph()
     {
         Nodes = new List<InteractionNode>();
     }
 }
 
 public class Interactable : MonoBehaviour
 {
 
     [HideInInspector]
     public InteractionGraph interactionGraph;
 
     public Texture2D cursorTexture;
 
     [SerializeField]
     private Vector2 _DialogPosition;
     public Vector2 DialogPosition
     {
         get
         {
             return transform.TransformPoint(new Vector3(_DialogPosition.x, _DialogPosition.y, 0f));
         }
         set
         {
             _DialogPosition = transform.InverseTransformPoint(new Vector3(value.x, value.y, 0f));
         }
     }
 
 }

I have a custom editor for Interactables, which works just fine:

 [CustomEditor(typeof(Interactable), true)]
 public class InteractableEditor : Editor
 {
     void OnSceneGUI()
     {
         var stuff = target as Interactable;
 
         //talk pos
         Undo.RecordObject(target, "dialog position changed");
         stuff.DialogPosition = Handles.DoPositionHandle(stuff.DialogPosition, Quaternion.identity);
         Handles.Label(stuff.DialogPosition, "dialog");
     }
 }
 

And finally here's the EditorWindow (I have commented out everything now I'm only trying to trigger the change tracking):

 public class ScriptNodesEditor : EditorWindow
 {
     private static ScriptNodesEditor nodeScriptEditorWindow;
 
 [MenuItem("Window/MyEditor")]
     static void ShowEditor()
     {
         nodeScriptEditorWindow = GetWindow<ScriptNodesEditor>();
     }

     void OnSelectionChange()
     {
         Repaint();
     }
 
     void OnGUI()
     {
         if (Selection.activeGameObject != null)
         {
             var interactable = Selection.activeGameObject.GetComponent<Interactable>();
             Undo.RecordObject(interactable, "change");
         }
     }
 }

Now this should trigger the change on every OnGUI call, right? Nothing is happening.

Instead of Undo.RecordObject(interactable) I tried calling

  • Undo.RecordObject(Selection.activeGameObject, "")

  • EditorUtility.SetDirty(interactable)

  • EditorUtility.SetDirty(Selection.activeGameObject)

None worked so far.

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 tenshiko · Sep 02, 2016 at 09:38 AM

Found the answer.

In short: properties are not serialized. I changed the properties to public fields and everything is fine.

In more detail... When you use Undo.RecordObject() a snapshot will be generated (through serialization) of the model you are passing to this method, and when Unity checks if anything is changed on your model it will compare the snapshot taken earlier with the current model. Since the c# properties are not serialized, they won't show up on the snapshot, therefore changes on those will not be noticed.

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

102 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

Related Questions

Unity 2017 or 5.6 Doesn't work after install. Editor is broken. 0 Answers

Undo.RecordObject doesn't work 3 Answers

How to Undo a bool on an EditorWindow 1 Answer

How do i fix my problem with minimizing/maximizing and just opening unity editor windows? 0 Answers

Weird Pink patches on my screen,Unity Color Glitch 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