I'm trying to record an action replay for the last 5 seconds. I'm building a bowling game and want to perform an action replay for when the ball strikes the pin by capturing with camera's with different angles. I'm unaware of how this thing could be done. Do i have to record a clip at run time for that and play it at the right time to display action replay? or something else?

Below is the code. Please refer to it.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Replay : MonoBehaviour

    public Text timertext;

    public GameObject pin1;
    public GameObject pin2;
    public GameObject pin3;
    public GameObject pin4;
    public GameObject pin5;
    public GameObject pin6;
    public GameObject pin7;
    public GameObject pin8;
    public GameObject pin9;
    public GameObject pin10;

    static int count = 50;

    Vector3 pin1po;
    Vector3 pin2po;
    Vector3 pin3po;
    Vector3 pin4po;
    Vector3 pin5po;
    Vector3 pin9po;
    Vector3 pin10po;

    List<Vector3> PinsPosition1;
    List<Vector3> PinsPosition2;
    List<Vector3> PinsPosition3;
    List<Vector3> PinsPosition4;
    List<Vector3> PinsPosition5;
    List<Vector3> PinsPosition6;
    List<Vector3> PinsPosition7;
    List<Vector3> PinsPosition8;
    List<Vector3> PinsPosition9;
    List<Vector3> PinsPosition10;

    List<Quaternion> PinsRotation1;
    List<Quaternion> PinsRotation2;
    List<Quaternion> PinsRotation3;
    List<Quaternion> PinsRotation4;
    List<Quaternion> PinsRotation5;
    List<Quaternion> PinsRotation6;
    List<Quaternion> PinsRotation7;
    List<Quaternion> PinsRotation8;
    List<Quaternion> PinsRotation9;
    List<Quaternion> PinsRotation10;

    public static bool start;

    // Use this for initialization
    void Start()

        start = false;

        pin1po = new Vector3();
        pin2po = new Vector3();
        pin3po = new Vector3();
        pin4po = new Vector3();
        pin5po = new Vector3();
        pin9po = new Vector3();
        pin10po = new Vector3();

        PinsPosition1 = new List<Vector3>();
        PinsPosition2 = new List<Vector3>();
        PinsPosition3 = new List<Vector3>();
        PinsPosition4 = new List<Vector3>();
        PinsPosition5 = new List<Vector3>();
        PinsPosition6 = new List<Vector3>();
        PinsPosition7 = new List<Vector3>();
        PinsPosition8 = new List<Vector3>();
        PinsPosition9 = new List<Vector3>();
        PinsPosition10 = new List<Vector3>();

        PinsRotation1 = new List<Quaternion>();
        PinsRotation2 = new List<Quaternion>();
        PinsRotation3 = new List<Quaternion>();
        PinsRotation4 = new List<Quaternion>();
        PinsRotation5 = new List<Quaternion>();
        PinsRotation6 = new List<Quaternion>();
        PinsRotation7 = new List<Quaternion>();
        PinsRotation8 = new List<Quaternion>();
        PinsRotation9 = new List<Quaternion>();
        PinsRotation10 = new List<Quaternion>();

        pin1po = pin1.transform.position;
        pin2po = pin2.transform.position;
        pin3po = pin3.transform.position;
        pin4po = pin4.transform.position;
        pin5po = pin5.transform.position;
        pin9po = pin9.transform.position;
        pin10po = pin10.transform.position;


    public void Checktime(bool time)
        start = time;


    // Update is called once per frame
    void Update()


    private void FixedUpdate()
        if (start == true)
            count = count - 1;

            if (count < 1)

















1 Answer 1


Rendering the scene from multiple angles at once in case the player wants to see a replay might be quite performance-intense. Also, you won't have enough memory to do that. 1920px * 1080px * 3 byte per pixel * 5 seconds * 60 frames per second * 10 perspectives = 17 GB of memory. Well, you could try to compress the videos in real-time, but that will make it even slower and will impair quality.

What I would suggest instead is to add a script Recorder to each replay-relevant game object which saves the transform.position and transform.rotation of the game object on each Update to a List.

In "Replay Mode", you disable all components which control the position of these objects and replace them with a script Replayer which then processes the list of transforms the Recorder saved update-by-update.

You can then replay the clip as often as you want with the camera in any position you like. You can even let the player control the camera during replay.

  • \$\begingroup\$ You mean to say that i should make a script that records the position of the ball and the pins and its collision, but how would i save the scene? \$\endgroup\$ May 16, 2017 at 11:13
  • \$\begingroup\$ @user100020 Yes, that's what I mean. What exactly do you mean with "save the scene"? In a bowling game, you would reset the scene after each throw anyway. \$\endgroup\$
    – Philipp
    May 16, 2017 at 11:17
  • \$\begingroup\$ @user100020 I don't understand what you are asking. Can you please rephrase it? \$\endgroup\$
    – Philipp
    May 16, 2017 at 11:21
  • \$\begingroup\$ You asked to save the values of rotation and position of the gameObjects, that's what i understood. But those would be the values only. Does that mean that i have to create a separate scene for that and initially apply those values(i.e position and rotation of the game objects) to that particular scene? \$\endgroup\$ May 16, 2017 at 11:26
  • \$\begingroup\$ Your scene likely has more than just the pins and the bowling ball. So I would reload the scene, load the pin configuration at the start of the throw, and then let the Replayer scripts do their thing while giving the player some camera and playback controls. There are several ways to do that. You could have multiple scenes which you load and unload additively (one for the environment which never changes and one for the pins and ball), or you could have everything in one scene and activate, deactivate or re-Instantiate things as needed. \$\endgroup\$
    – Philipp
    May 16, 2017 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .