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 KneesWeak · Feb 09, 2017 at 03:41 PM · editorundorecord

Undo.RecordObject doesn't work

Hello,

I want to implent an undo/redo-system in a 3D virtual reality editor. I already used Undo.RegisterCreatedObjectUndo to register when a new object is created and make the action undoable. However I can not get the essential Undo.RecordObject to work, here is an example:

  Undo.RecordObject(GetComponent<LaserPointer>().hitObject, "ObjectMoved");
  OnTriggerDownMove(GetComponent<LaserPointer>().hitObject);

In this example I simply target an GameObject with the laserpointer (attached to the controller) and move it by holding the trigger and dragging it. Undo.RecordObject does not register any undo-operation for that.

If I use the Undo.RegisterCompleteObjectUndo function, I can use Undo.performUndo to reset the position, however it only allows to save 1 copy of the object and multiple move-steps will not be undoable step-wise.

I hope you guys can help me out, if you need additional information just tell me.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Adam-Mechtley · Feb 09, 2017 at 06:46 PM

It sounds like you are changing properties on the Transform component, but recording the state of the LaserPointer component. Make sure you pass the affected Transform component to the Undo.RecordObject() method.

Comment
Add comment · Show 1 · 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 KneesWeak · Feb 11, 2017 at 08:06 AM 0
Share

Hey, thanks for your answer. I managed to partly get the Undo.RecordObject() function to work now. I placed it inside the OnTriggerDown$$anonymous$$ove() function and used the transform of the given GameObject:

 public void OnTriggerDown$$anonymous$$ove(GameObject hitObject)
     {
             Undo.RecordObject(hitObject.transform, "Obejct$$anonymous$$oved");
            /*...rest of the function...*/
 }

However it has the following problem: When I move the object from a to b and then use performUndo(), the object will be reset too position a and everything seems fine. But when I move the object from a to b and then I move the object from b to c (the object can be grabbed and moved multiple times) and then I use performUndo(), the object will always be reset to position a, even if the starting-position of the last move was somewhere else. Any ideas?

avatar image
0

Answer by KneesWeak · Feb 12, 2017 at 08:59 AM

I managed to partly get the Undo.RecordObject() function to work now. I placed it inside the OnTriggerDownMove() function and used the transform of the given GameObject:

 public void OnTriggerDownMove(GameObject hitObject)
     {
             Undo.RecordObject(hitObject.transform, "ObejctMoved");
            /*...rest of the function...*/
 }

However it has the following problem: When I move the object from a to b and then use performUndo(), the object will be reset too position a and everything seems fine. But when I move the object from a to b and then I move the object from b to c (the object can be grabbed and moved multiple times) and then I use performUndo(), the object will always be reset to position a, even if the starting-position of the last move was somewhere else. Any ideas?

Comment
Add comment · Show 2 · 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 Adam-Mechtley · Feb 13, 2017 at 09:05 AM 1
Share

Could you try calling Undo.IncrementCurrentGroup() each time the trigger button is first depressed?

avatar image KneesWeak Adam-Mechtley · Feb 13, 2017 at 03:36 PM 0
Share

Thanks a lot! This worked perfectly. So far I have some trouble really understanding the Groups of the Undo Element. Sadly the documentation doesn't really help me...

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Undo.Record: Recording variables within array elements 0 Answers

Constant error : SaveSnapshot called without previous call to MakeSnapshot 1 Answer

Need help reassigning variables after the deletion of an object has been undone. 0 Answers

Undo in Editor only executed when I switch focus to Hierarchy 0 Answers

Custom data for undo/redo action? 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