how to perform undo action in unity?

I have tried to perform undo action but actually it was working once in editor mode .
Also it was not working on device.
I want to track object position, rotation and enabling/disabling gameObject .
Thanks in advance.

Mac: Command + Z

Windows: Ctrl + Z

Sometimes it doesn’t work if you undo too many times because there is a limit to how far you can go back. And some things simply cant be undone.

To anyone still trying to undo a SetActive() action, using Undo.RegisterFullObjectHierarchyUndo() worked for me where Undo.RecordObject() did not.