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
0
Question by Bovine · Oct 30, 2011 at 03:06 PM · editorwindowundoempty

Why do I get an empty Undo for my EditorWindow?

Hi There

I have Undo/Redo working for my EditorWindow, but the very first thing I undo appears to be nothing, i.e. an Empty Undo. I'll detail the scenario below, all help appreciated.

I have a node based EditorWindow or my Behaviour Tree implementation. When one of my nodes is moved I record the rect on the node class (serialisable) which is part of a hierarchy on a ScriptableObject. In OnGUI I also detect whether a node is added or deleted and I detect GUI changes as well as seems to be the case for the example code from the help.

So in On GUI I have something like:

    void OnGUI()
    {  // get the selection
       BVTreeDescription tree = Selection.activeObject as BVTreeDescription;
       if(tree == null)
       {  // clear tree
          m_tree = null;
          return;
       }
       
       // use this tree
       m_tree = tree;
       
       // we want to update on scene change
       autoRepaintOnSceneChange = true;
       
       // handle undo
       Undo.SetSnapshotTarget(m_tree, "Editing Behaviour Tree");
       
       // no rects changed yet, or nodes added
       m_nodes_changed = false;
       m_rect_changed = false;
 
       // *** The GUI is rendered here but it's a lot of code so I've cut it! ***
 
       // the behaviour tree view
       m_scroll_pos = GUI.BeginScrollView(scroll_area, m_scroll_pos, m_required_area);
   
       // behaviour tree nodes
       BeginWindows();
       RenderNode(m_tree.Root, null);   // will render all children as well
       EndWindows();
       
       // end view
       GUI.EndScrollView();
       
       // save asset if edited!
       if(GUI.changed || m_nodes_changed || m_rect_changed)
       {  // dirty!
          EditorUtility.SetDirty(m_tree);
 
          // and save the snapshot
          Undo.CreateSnapshot();
          Undo.RegisterSnapshot();
 
          // force a repaint - I maybe need this if the nodes changed?
          Repaint();
       }
       else
       {
          Undo.ClearSnapshotTarget(); // totally unsure whether this is doing anything!
       }
    }

So I've cut the guts of the code because it's quite a lot and probably not relecant, but basically does my Undo logic look broadly right? FYI, each node is rendered using GUILayout.Window(). And for reference looks broadly like this:

Behaviour Tree Image

it all works other than I just get an empty undo at the very end, so the first thing I undo changes nothing, but the next undo is the first expected undo. Weirdly, if I just drag a window and then undo, the first undo DOES undo the window's rect position. If however, I change the node type from say Action to Condition, then the first undo is empty. I've added logging in the if clause at the end and it's only being called once it seems and I've tried moving the actual to its own if clause, more in line with the example from docs, but in that case when I change the node type this does not get undone (so setting an asset to dirty does not give you free undo for an EditorWindow).

I feel something isn't quite right but I can't see where I might be going wrong. Has anyone else come across this issue?

Again, all help appreciated! Bovine

Comment
Add comment · Show 1
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 Bovine · Oct 30, 2011 at 03:13 PM 0
Share

Hmmmm... I moved the call to Undo.CreateSnapshot() after the SetSnapshotTarget() and it all works fine. Should it? This is NOT what the documentation example is doing :o/

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

2 People are following this question.

avatar image avatar image

Related Questions

Editing and Undo for non-unity properties 2 Answers

How do you undo operations from an EditorWindow? 1 Answer

Undo problems with a Custom EditorWindow 0 Answers

Undo issues in EditorWindow 0 Answers

Repaint on Undo 5 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