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
3
Question by SebastianPatric · Jan 28, 2014 at 07:37 AM · editorunityeditoreditor-scriptingundo

How to deal with object deletion Undo states and variables referencing the objects involved?

This is an editor scripting question. Say I have a List (edit - Built in Array) of GameObjects. I have the user of my editor extension delete some of them from the scene. I register that deletion with the Undo system by using: Undo.DestroyImmediate(MyObject). At the time of deletion I also remove the objects from my List (edit - Built in Array). When the user then presses 'Undo', the objects are re-created by Unity's built in processes. How can I restore them to my list(edit - Built in Array)?

Comment
Add comment · Show 4
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 SebastianPatric · Jan 29, 2014 at 12:07 AM 0
Share

BTW, the objects in question are created by my editor extension and added to the List (edit- Built in Array). Their creation is registered with the Undo system via Undo.RegisterCreatedObjectUndo(myObject,"$$anonymous$$yObjectCreated"). I would similarly be interested if their addition to the list (edit - Built in Array) could also be registered. It's basically the same question, but in reverse. On the one hand, If I could catch the undo event for objects being created (ie. when the user undoes object creation), I could then verify the List(edit - Built in Array) by checking what is in the scene, but what I'm really after is a more direct way of knowing what's being undone/redone (un-created/re-created) so I can get my List(edit - Built in Array) updated accordingly in both cases. This would come in handy in so many situations.

avatar image SebastianPatric · Jan 30, 2014 at 11:25 PM 0
Share

I edited my question to specify that I'm actually using a Built in Array. I realize that Lists are not serialized by Unity, making them incapable of registering with the Undo system. I didn't want anyone to think that this was the crux of my issue. I also want to point out that the Array in question lives in a script on a hidden object that is always in the scene, not in the editor class. So the only thing I'm looking for is how I can re-populate my array with objects that were in it before being deleted and then then restored with Undo.

I was thinking that, as an alternative to using the Undo system to manage my array directly, I could potentially catch the undo event and then compare what's in the scene at the time to a separate array of all objects that have ever been created by my script. Based on that comparison, I can then update my main array of existing objects belonging to my editor extension. This way I would always be doing scene checks to manage my array ins$$anonymous$$d of ever registering the array with the Undo system. The downside is that the array of all stuff ever created by my script would likely get too huge to use efficiently. So this is not an ideal solution.

avatar image Acegikmo · Apr 02, 2014 at 03:01 PM 0
Share

I just wanted to jump in and say that I have the same issues. It's not related to List, most likely. I've serialized it a lot before (I'm using it in my plugin Shader Forge), without any issues.

It's a node based shader editor, and my issues are related to undoing the deletion of nodes. Each node is also in a List inside a node manager.

The strange part is that I can undo adding nodes, and then redo, which is essentially the same as undoing deletion of a node. (Restoring a lost object and re-adding it to a list without breaking references)

I did try and get this to work in an isolated case, and it actually worked, but I can't get it to work in Shader Forge just yet.

I'll let you know if I can get things to work!

avatar image vexe · May 13, 2014 at 10:18 PM 0
Share

This is the exact problem I had a while back. See here. I managed to reach a 50/50 chance of getting a successful undo.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Nims · Apr 24, 2014 at 05:31 AM

I think this is relevant to this question:

http://feedback.unity3d.com/suggestions/extend-undo-to-support-actions-command-pattern

Here are just a few thoughts @SebastianPatric:

  1. Implement your own undo/redo system in your editor. So you will need to add Undo/Redo buttons to your editor window.

  2. Make your base items of the list/array seriliazable.

  3. Define a custom class - to record the actions done in your editor window - with some actions like create,delete etc (Enums?), with each action taking in the relevant info (A deep copy of the instance of your list item - this could be a serialized version of the instance?).

  4. Define a stack of of type action in the custom class - This could be a static variable of the custom class. Whenever an action is taken in your editor, create the appropriate action object and push it to the stack.

  5. Add Undo/Redo functions linked to the buttons in the editor with their implementation for the Undo/Redo the action.

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 dahodd · Feb 06, 2015 at 10:04 AM

You most likely do an undo on a database or file. You have to repopulate the array from data source after undo.

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

22 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

Related Questions

Undo.RecordObject isn't working. 7 Answers

How to properly handle Undo events in custom inspector? 0 Answers

how to stop reorderable list from passing Event value to the new element 1 Answer

Create a custom window and set his position on second screen 1 Answer

How to undo removing components in an editor extension? 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