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 /
avatar image
0
Question by killerloader · Jul 14, 2017 at 03:31 PM · custom editorundocorruptedunity 5.1.1

Unity 5.1.1f1: Redo operation in custom editor causes some sort of corruption.

I'm trying to implement undo/ redo operations into my custom editor. Essentially, the editor has a reference to a monobehaviour, and it directly edits this, and does Undo.RecordObject on it before changing things.

So my problem starts when i redo something that I've undone. My monobehaviour has a list of a certain serializable object, and those objects have another list of another serializable object. When i use RemoveAt on the first list (i record the undo directly beforehand), it works fine, and it allows me to undo it. But then when i redo the change, some of the data in a different list ID changes. For example, if i use removeat on object.list1[0] then some of the data in object.list1[5] gets corrupted after i undo then redo. Specifically, the data in object.list1[5].list2[#] (But not all of the data) The size of the lists stay the same, but the data in the list2 objects get reset to 0 or ""

If i run my custom editor with a reference to a prefab monobehaviour, it works fine. It's just when i run the custom editor with a reference to a monobehaviour that is currently in the scene.

All the data in the object seems to get correctly serialized. (If i change something in the editor, then save and reload unity, it sicks. And applying and reverting the object to the prefab also works correctly)

So it seems as if unity doesn't have an up to date serialization of my monobehaviour before the undo is stored, and then it gets mucked up when the redo occurs. Although, because only some of the data gets corrupted, that might be unlikely. Also, it seems that only items in list2 get corrupted when their list ID is greater than 2.

This is my first time doing custom editors and recording object changes, so hopefully i didn't miss something completely obvious..

If code is needed, i will try to create a minimal code example when i get time.

tl;dr - Redo breaks scene object but not prefab object. - Deleting and item from a list is what causes the redo/ undo to go weird. - The items within other elements of that list get corrupted after the redo.

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
Best Answer

Answer by killerloader · Aug 02, 2017 at 09:58 AM

I suppose the correct answer to this is to use a SerializedObject to make the changes. The first time i researched it, i didn't realise that you could go deeper into the properties by doing "FindPropertyRelative"

I did find a fix for using my previous method, although it's probably bad practice, but this seemed to work:

 Undo.RecordObject(dialogue, "Reset Dialogue");
 EditorUtility.SetDirty(dialogue);
 //Changes here

This stopped the corruption. Although now i'm using this method and serialised objects at the same time, so i will probably slowly convert it all to serialised objects.

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

69 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

Related Questions

Undo.Record: Recording variables within array elements 0 Answers

Custom Inspector Undo Functionality when directly changing SerializedProperties 1 Answer

CustomPropertyDrawer undoable properties 1 Answer

How to Undo SharedMaterial set in CustomEditor? 1 Answer

Undo.RegisterFullObjectHierarchyUndo not working 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