Is it possible to rewind events in your game?

I have a pause button that jumps in to the middle of the screen when it is pressed and then pops and moves a bunch of objects around in the scene. When the play button is pressed to resume play I want all the objects that were moved to go back to their initial positions before the pop. Kind of like rewinding a movie.

Can someone point me in the right direction to get started with this?

The only way to make a rewind function is to track the status of each GameObject. Unity doesn’t support this natively, you have to code it on your own.

There are some possible implementations here

There are two things that you could want.

  1. You want to set the objects to a new position and then when you “rewind” the objects are moved from point B to point A instantly.
  2. You want the objects to go to a new position on button pressed, and then when you rewind them you want them to go move backwards and gradually land at the old position.

Both are very possible, and the latter is only a little bit harder to implement.

        // Non-Monobehaviour; can easily be made into a Monobehaviour for a quicker implementation.
        // This class lacks that implementation that'll allow this to be completely optimized, but it'll work
        [System.Serializable]
        public class MovableObject
        {
            [SerializeField] GameObject _object = null;   // The GameObject
            Vector3 _oldPosition = new Vector3();    // The old Logged position

            // Moves the object to a target position
            public void Move_Object(Vector3 newPos)
            {
                _oldPosition = _object.transform.position;
                // Move the object using whatever logic you want
            }

            public void Reset_Position()
            {
                _object.transform.position = _oldPosition;
            }
        }


        /// ANOTHER SCRIPT FILE

        public class MoveObjects
        {
            public System.Collections.Generic.List<MovableObject> movableObjects = new System.Collections.Generic.List<MovableObject>();

            void Update()
            {
                if (buttonSetToPlay)        // If button is pressed
                {
                    foreach (MovableObject o in movableObjects)
                    {
                        if (o != null)
                        {
                            o.Move_Object(desiredPosition);         // Come up with a semi-random position
                        }
                    }
                }

                else if (buttonIsReset)
                {
                    foreach (MovableObject o in movableObjects)
                    {
                        if (o != null)
                        {
                            o.Reset_Position()        // Come up with a semi-random position
                        }
                    }
                }
            }
        }

class MovableObject holds all of the data for the GameObject including the old position.

class MoveObjects actually moves the objects based on when / how the GUI was pressed.

The way it currently is set up will allow for #1 to work. #2 would work as well with this, but you’d have to add in a few Coroutines that will Lerp the object from position B to position A.

There are about 200 ways to implement it. This is 1 of them.