- Home /
Undo in playmode
Hi, I've gotten undo to work just fine with RegisterUndo.
However, when I enter playmode, RegisterUndo no longer seems to work.. is that what's supposed to happen? And if so, is there a work around?
RegisterUndo is a function for working with the undo functionality in the Editor! You'll need to write your own Undo system if you want it to work in game.
Answer by Julien-Lynge · Nov 27, 2011 at 01:58 AM
Sharsnik, There is no 'undo' functionality within the Unity editor's runtime environment, nor are most changes you make there saved - once you hit play, Unity changes to more of a sandbox mode.
If you don't like this sandbox mode and think Unity should change it, there are entries on the Unity wishlist asking for it to be changed, though I don't know of any specifically asking to add an undo functionality to the runtime. My guess is that you'd get some support suggesting it as a feature - my team has definitely been annoyed by it now and then.
I disagree about persistant changes in the editor's runtime- It's quite common for events in game (be they bugs or genuine behaviur) that make significant changes to the environment, and it would be a source of unending frustration if you had to reset everything by hand. For example, if I have a pristine world filled with stacked rigidbodies that the player then runs through and completely wrecks, it would take hours fixing it without special code for saving the initial state of every object in the scene at the start.
Having an undo function specifically for changes that the user makes in the inspector would be useful, but since at runtime the game itself can make sudden and unexpected changes, how does the editor know that it is setting things back to the 'correct' value when you hit undo? I think allowing the functionality at runtime would cause more trouble than good.