Scripting API

The static RCC class is RCC's main public API. Every common runtime operation — spawning a vehicle, registering a player, switching cameras, repairing damage, transporting a car — has a method here. This document covers every public method, when to use it, and shows working code examples.

If you're writing game code that talks to RCC, this is the class you talk to.

Where the API Lives

Assets/RealisticCarControllerV4/Scripts/RCC.cs

It's a plain static class with no instance — call methods directly on the type: RCC.SpawnRCC(...).

Spawning Vehicles

SpawnRCC

public static RCC_CarControllerV4 SpawnRCC(
    RCC_CarControllerV4 vehiclePrefab,
    Vector3 position,
    Quaternion rotation,
    bool registerAsPlayerVehicle,
    bool isControllable,
    bool isEngineRunning);

Instantiates a vehicle prefab at the given pose and configures its control / engine state. Returns the spawned instance.

Parameter Purpose
vehiclePrefab The prefab to instantiate. Drag in a prefab from Prefabs/Vehicles/.
position Spawn position.
rotation Spawn rotation.
registerAsPlayerVehicle If true, the spawned vehicle becomes the active player. The camera will follow it.
isControllable If true, accepts player input. If false, the vehicle is inert (good for showroom display).
isEngineRunning If true, the engine is running at spawn (idling). If false, the engine is off until started manually.

Example: Spawn a vehicle from a car selection menu

public class CarSelectionDemo : MonoBehaviour {
    public RCC_CarControllerV4 selectedVehiclePrefab;
    public Transform spawnPoint;

    public void OnStartButtonPressed() {
        RCC_CarControllerV4 spawned = RCC.SpawnRCC(
            selectedVehiclePrefab,
            spawnPoint.position,
            spawnPoint.rotation,
            registerAsPlayerVehicle: true,
            isControllable: true,
            isEngineRunning: true);
        // spawned.gameObject is the spawned GameObject.
    }
}

Registering Vehicles

RegisterPlayerVehicle

Three overloads:

public static void RegisterPlayerVehicle(RCC_CarControllerV4 vehicle);
public static void RegisterPlayerVehicle(RCC_CarControllerV4 vehicle, bool isControllable);
public static void RegisterPlayerVehicle(RCC_CarControllerV4 vehicle, bool isControllable, bool engineState);

Promotes the given vehicle to be the active player vehicle. The camera follows it, the input system feeds it, and the HUD reflects its state.

Example: Switch the player vehicle after a transition

RCC.RegisterPlayerVehicle(anotherVehicle, isControllable: true, engineState: true);

The previous player vehicle is de-registered automatically.

DeRegisterPlayerVehicle

public static void DeRegisterPlayerVehicle();

Removes the current player vehicle from active duty. The camera stops following, input stops feeding. Useful at the end of a level or during a cinematic.

Controlling Vehicles

SetControl

public static void SetControl(RCC_CarControllerV4 vehicle, bool isControllable);

Enables / disables player input on a specific vehicle. Useful during pause menus, cutscenes, or before a race countdown.

Example: Disable control during a 3-2-1 countdown

void StartCountdown(RCC_CarControllerV4 vehicle) {
    RCC.SetControl(vehicle, false);
    StartCoroutine(CountdownAndGo(vehicle));
}

IEnumerator CountdownAndGo(RCC_CarControllerV4 vehicle) {
    yield return new WaitForSeconds(3f);
    RCC.SetControl(vehicle, true);
}

SetEngine

public static void SetEngine(RCC_CarControllerV4 vehicle, bool engineState);

Starts (true) or kills (false) the engine.

Example: Engine ignition gameplay

void OnPlayerEntersCar(RCC_CarControllerV4 vehicle) {
    RCC.SetEngine(vehicle, false); // engine off — needs key turn
    StartCoroutine(WaitForKeyTurn(vehicle));
}

Behavior

SetBehavior

public static void SetBehavior(int behaviorIndex);

Switches the global driving behavior preset. The index is into RCC_Settings.behaviorTypes[]. See 10 — Behavior Presets.

Example: Settings menu changes difficulty

void OnDifficultyDropdownChanged(int newValue) {
    RCC.SetBehavior(newValue); // 0 = Realistic, 4 = Arcade
}

Camera

ChangeCamera

public static void ChangeCamera();

Cycles the camera mode (TPS → Hood → Wheel → Fixed → Cinematic → Top → TPS).

Example: A "next camera" button on screen

void OnCameraButtonPressed() {
    RCC.ChangeCamera();
}

Transport / Teleport

Transport

Two overloads:

public static void Transport(Vector3 position, Quaternion rotation);
public static void Transport(RCC_CarControllerV4 vehicle, Vector3 position, Quaternion rotation);

Moves the player vehicle (or a specific vehicle) to a target pose. The vehicle's velocity is zeroed so it doesn't continue moving after the teleport.

Example: Teleport to a respawn point

public void RespawnPlayer() {
    Transform respawn = GetClosestRespawnPoint();
    RCC.Transport(respawn.position, respawn.rotation);
}

Skidmarks

CleanSkidmarks

Two overloads:

public static void CleanSkidmarks();
public static void CleanSkidmarks(int index);

Clears all skidmarks in the scene, or just the ones for a specific batch index.

Example: Clear skidmarks each lap

void OnLapCompleted() {
    RCC.CleanSkidmarks();
}

Repair

Repair

Two overloads:

public static void Repair(RCC_CarControllerV4 carController);
public static void Repair(); // repairs the active player vehicle

Instantly resets damage on a vehicle — mesh deformation, detachable parts, wheel alignment, and broken lights are all restored.

Example: Repair on driving over a repair zone

void OnTriggerEnter(Collider other) {
    RCC_CarControllerV4 vehicle = other.GetComponentInParent<RCC_CarControllerV4>();
    if (vehicle != null) {
        RCC.Repair(vehicle);
    }
}

Record / Replay

StartStopRecord

public static void StartStopRecord();

Toggles recording on the active player vehicle. If recording is off, starts a new recording; if on, stops it. The recording captures position, rotation, and inputs each frame.

StartStopReplay

public static void StartStopReplay();

Plays back the most recently recorded clip.

StopRecordReplay

public static void StopRecordReplay();

Stops the current recording or replay session.

Example: A "record my lap" button

public void OnRecordButtonPressed() {
    RCC.StartStopRecord();
}

public void OnReplayButtonPressed() {
    RCC.StartStopReplay();
}

Mobile Controller

SetMobileController

public static void SetMobileController(RCC_Settings.MobileController mobileController);

Switches the mobile input style at runtime.

Example: Settings menu mobile control toggle

public void OnControllerStyleDropdownChanged(int value) {
    var style = (RCC_Settings.MobileController)value;
    RCC.SetMobileController(style);
}

Not Yet Implemented (Future)

These methods exist as placeholders and currently do nothing. Don't depend on them in production code — their behavior may change:

If you need this functionality today, set the underlying fields directly:

RCC_Settings.Instance.units = RCC_Settings.Units.MPH;
carController.automaticGear = true;

Common API Patterns

Get the Active Player Vehicle

RCC_CarControllerV4 player = RCC_SceneManager.Instance.activePlayerVehicle;
if (player != null) {
    // do something with the player vehicle
}

Get All Vehicles in the Scene

List<RCC_CarControllerV4> all = RCC_SceneManager.Instance.allVehicles;
foreach (var v in all) {
    Debug.Log(v.name + " is at " + v.transform.position);
}

Read Vehicle State

RCC_CarControllerV4 v = RCC_SceneManager.Instance.activePlayerVehicle;
float speed = v.speed;             // current speed
float rpm = v.engineRPM;           // current engine RPM
int gear = v.currentGear;          // current gear index
bool inReverse = (v.direction == -1);
bool grounded = v.isGrounded;

Read Current Inputs

RCC_Inputs current = RCC_InputManager.Instance.GetInputs();
float throttle = current.throttleInput;
float brake = current.brakeInput;
float steer = current.steerInput;

Modify Inputs

For overriding the player, see 17 — Overriding Inputs.

What's Not in the Static API

A few operations don't have static helpers on RCC and must be done directly:

The static RCC class is intentionally minimal — it covers the most common operations. For finer control, you have access to every method on the underlying components.

Concurrency Notes

All RCC static methods must be called from the main Unity thread. Don't call them from background threads or Task / async contexts — Unity throws if you do.

If you're using async / await in your game code, make sure your continuations come back to the main thread before calling RCC methods (use await UniTask.SwitchToMainThread() if you use UniTask, or post to Unity's main thread via your own dispatcher).

Next Steps