Recording and Playback

Table of Contents

RCCP includes a built-in recording and playback system that captures vehicle movement and inputs at the physics framerate. You can record a driving session and replay it exactly, including throttle, brake, steering, gear changes, light states, and rigidbody velocities. Recordings can be saved persistently to a ScriptableObject asset for reuse across play sessions.

Prerequisites: The vehicle must have the RCCP_OtherAddons component, which provides access to the RCCP_Recorder. See Vehicle Setup for configuring a complete vehicle.

How Recording Works

The RCCP_Recorder component captures three types of data every FixedUpdate frame:

Data TypeClassWhat It Stores
Vehicle InputVehicleInputThrottle, brake, steer, handbrake, clutch, NOS, direction, current gear, gear state, neutral gear flag, low beam, high beam, left/right/all indicators
Vehicle TransformVehicleTransformWorld position and rotation
Vehicle VelocityVehicleVelocityRigidbody linear velocity and angular velocity

These three arrays are stored together in a RecordedClip object. During playback, the recorder feeds these values back into the vehicle frame by frame, reproducing the original driving session.

Recorder Modes

The recorder operates in one of three modes:

ModeDescription
NeutralIdle state. No recording or playback in progress.
RecordActively capturing input, transform, and velocity data every physics frame.
PlayPlaying back a previously recorded clip. Vehicle input and gearbox are overridden.

The RCCP_Recorder Component

RCCP_Recorder inherits from RCCP_Component and is part of the RCCP_OtherAddons system. It is accessed at runtime through vehicle.OtherAddonsManager.Recorder.

Key Fields

FieldTypeDescription
recordedRecordedClipThe most recently saved or loaded recorded clip
modeRecorderModeCurrent operational mode (Neutral, Record, or Play)

Recording a Session

Using the Keyboard

RCCP maps recording to the Optional action map in the Input System. The default key bindings are:

ActionDefault KeyDescription
RecordRToggle recording on/off
ReplayPToggle playback of the last recorded clip

These bindings are defined in the RCCP_InputActions asset and can be customized through the Unity Input System settings.

Using the API

The RCCP static class provides convenience methods for recording:


// Start recording (call again to stop and save)
RCCP.StartStopRecord(myVehicle);

// Start/stop replay of the last recorded clip
RCCP.StartStopReplay(myVehicle);

// Replay a specific recorded clip
RCCP.StartStopReplay(myVehicle, specificClip);

// Stop both recording and playback
RCCP.StopRecordReplay(myVehicle);

Using the Recorder Directly

You can also call methods on the RCCP_Recorder component directly:


RCCP_Recorder recorder = myVehicle.OtherAddonsManager.Recorder;

// Toggle recording
recorder.Record();

// Toggle playback of last recorded clip
recorder.Play();

// Play a specific clip
recorder.Play(myClip);

// Stop everything and return to neutral
recorder.Stop();

Playback Details

When playback starts, the recorder:

  1. Sets the vehicle to overridePlayerInputs and overrideExternalInputs so recorded data takes full control
  2. Overrides the gearbox so recorded gear changes are replayed
  3. Moves the vehicle to the first recorded position and rotation
  4. Feeds recorded inputs, velocities, and gear states frame by frame in WaitForFixedUpdate coroutines

When playback finishes (all frames consumed) or is stopped manually, the recorder:

  1. Returns to Neutral mode
  2. Restores normal player input and gearbox control

Important: Playback starts from the first recorded position. The vehicle is automatically teleported to that position when playback begins.

Saving and Loading Recordings

RCCP_Records ScriptableObject

Recorded clips are automatically saved to the RCCP_Records ScriptableObject when recording stops. This asset is located at:


Assets/Realistic Car Controller Pro/Resources/RCCP_Records.asset

It is loaded via RCCP_Records.Instance (a singleton pattern using Resources.Load).

FieldTypeDescription
recordsList\All saved recorded clips

Each RecordedClip has a recordName field that is auto-generated as {index}_{vehicleName} when saved.

Playing a Saved Recording


// Get all saved recordings
List<RCCP_Recorder.RecordedClip> allRecords = RCCP_Records.Instance.records;

// Play the first saved recording
if (allRecords.Count > 0) {
    RCCP.StartStopReplay(myVehicle, allRecords[0]);
}

Note on Persistence

RCCP_Records is a ScriptableObject asset. In the Unity Editor, recordings saved during Play Mode will persist to the asset file. In a built game, ScriptableObject data does not persist between sessions unless you implement your own serialization. For runtime persistence in builds, consider serializing the RecordedClip data to JSON or binary files.

Complete Example


using UnityEngine;

public class RecordingExample : MonoBehaviour {

    public RCCP_CarController myVehicle;

    void Update() {
        // Press F5 to toggle recording
        if (Input.GetKeyDown(KeyCode.F5)) {
            RCCP.StartStopRecord(myVehicle);
        }

        // Press F6 to toggle replay
        if (Input.GetKeyDown(KeyCode.F6)) {
            RCCP.StartStopReplay(myVehicle);
        }

        // Press F7 to stop everything
        if (Input.GetKeyDown(KeyCode.F7)) {
            RCCP.StopRecordReplay(myVehicle);
        }
    }
}

RecordedClip Data Structure

For advanced users who want to inspect or manipulate recording data:


[System.Serializable]
public class RecordedClip {
    public string recordName;
    public VehicleInput[] inputs;       // Per-frame input data
    public VehicleTransform[] transforms; // Per-frame position/rotation
    public VehicleVelocity[] rigids;     // Per-frame velocity data
}

VehicleInput Fields

FieldTypeDescription
throttleInputfloatThrottle amount (0-1)
brakeInputfloatBrake amount (0-1)
steerInputfloatSteering amount (-1 to 1)
handbrakeInputfloatHandbrake amount (0-1)
clutchInputfloatClutch amount (0-1)
nosInputfloatNitrous input (0-1)
directionintDrive direction (1 = forward, -1 = reverse)
currentGearintCurrent gear index
gearStateGearStateGearbox state enum
NGearboolWhether neutral gear is engaged
lowBeamHeadLightsOnboolLow beam headlight state
highBeamHeadLightsOnboolHigh beam headlight state
indicatorsLeftboolLeft indicator state
indicatorsRightboolRight indicator state
indicatorsAllboolHazard lights (all indicators) state

VehicleTransform Fields

FieldTypeDescription
positionVector3World position of the vehicle
rotationQuaternionWorld rotation of the vehicle

VehicleVelocity Fields

FieldTypeDescription
velocityVector3Rigidbody linear velocity
angularVelocityVector3Rigidbody angular velocity

Common Issues

ProblemPossible CauseSolution
Recording not startingMissing RCCP_Recorder componentEnsure the vehicle has RCCP_OtherAddons which provides access to the Recorder
R key not triggering recordInput action not boundCheck that the Optional action map is enabled in RCCP_InputActions with the Record action bound to the R key
Replay looks jerkyInconsistent physics timestepEnsure a consistent Time.fixedDeltaTime value. Recording captures at the physics rate, so changes to the timestep during playback can cause uneven motion.
Vehicle teleports at replay startExpected behaviorPlayback always starts from the first recorded position. The vehicle is teleported there automatically.
Replay drifts from original pathPhysics nondeterminismSmall floating-point differences in physics can cause divergence over long replays. The velocity data helps reduce this, but perfect reproduction is not guaranteed over very long clips.
Recordings lost after restarting the game (build)ScriptableObject data does not persist in buildsImplement your own serialization (JSON, binary) to save RecordedClip data to disk in builds
Cannot access RecorderNull reference on OtherAddonsManagerAdd the RCCP_OtherAddons component to the vehicle. The Recorder is accessed through vehicle.OtherAddonsManager.Recorder.

Related topics: Vehicle Setup | Inputs | AI Vehicles | API Reference

Support: bonecrackergames@gmail.com | www.bonecrackergames.com

Need help? See Troubleshooting