Scene Management

Table of Contents

Overview

RCCP_SceneManager is the central singleton that manages all vehicles, the camera, and the UI canvas in your scene. It tracks which vehicle is the active player vehicle, maintains a list of all spawned vehicles, and handles vehicle registration/deregistration.

RCCP_SceneManager Properties

PropertyTypeDescription
activePlayerVehicleRCCP_CarControllerThe current player-controlled vehicle
activePlayerCameraRCCP_CameraThe active camera following the player
activePlayerCanvasRCCP_UIManagerThe active UI canvas
activeMainCameraCameraThe Unity main camera
allVehiclesList<RCCP_CarController>All vehicles currently in the scene

Access the scene manager anywhere via:


RCCP_SceneManager.Instance

Setting Up a Scene

Every scene that uses RCCP vehicles needs the following:

  1. RCCP_SceneManager — Vehicle registry singleton
  2. RCCP_SkidmarksManager — Manages tire marks on the ground
  3. RCCP_Camera — Camera system (optional but recommended)
  4. RCCP_UIManager — UI canvas (optional but recommended)

Add all of these via Tools > BoneCracker Games > RCCP > Create > Scene Managers (for the first two) and the individual create menu items for camera and UI.

If you skip the manual setup and spawn a vehicle as a player, RCCP will auto-instantiate the camera and UI from the prefabs in RCCP Settings.

Spawning Vehicles

Via Script (Recommended)

Use the static RCCP.SpawnRCC method to instantiate a vehicle from a prefab:


// Spawn as player vehicle (controllable, engine running)
RCCP_CarController vehicle = RCCP.SpawnRCC(
    vehiclePrefab,       // Reference to the vehicle prefab
    spawnPosition,       // Vector3 world position
    spawnRotation,       // Quaternion rotation
    registerAsPlayer: true,
    isControllable: true,
    engineRunning: true
);

// Spawn as AI vehicle (not player, not controllable)
RCCP_CarController aiVehicle = RCCP.SpawnRCC(
    vehiclePrefab,
    spawnPosition,
    spawnRotation,
    registerAsPlayer: false,
    isControllable: false,
    engineRunning: true
);

Via Scene Placement

You can also place vehicle prefabs directly in the scene hierarchy. If registerLastVehicleAsPlayer is enabled in RCCP Settings, the last vehicle added will automatically become the player vehicle.

Registering and Deregistering Players

Only one vehicle can be the active player vehicle at a time. Registering a new player vehicle automatically deregisters the previous one.

Register


// Register a vehicle as the player
RCCP.RegisterPlayerVehicle(vehicle);

// Register with options
RCCP.RegisterPlayerVehicle(vehicle, isControllable: true, engineRunning: true);

Deregister


// Remove the current player vehicle (camera and UI disconnect)
RCCP.DeRegisterPlayerVehicle();

Switch Between Vehicles


// Switch to a different vehicle
RCCP.RegisterPlayerVehicle(otherVehicle);
// The camera and UI automatically follow the new vehicle

Teleporting Vehicles

Move a vehicle instantly to a new position:


// Teleport the player vehicle
RCCP.Transport(newPosition, newRotation);

// Teleport any vehicle (with velocity reset)
RCCP.Transport(vehicle, newPosition, newRotation, resetVelocity: true);

Vehicle Events

RCCP fires events through the RCCP_Events system when vehicles are spawned, destroyed, or changed:


// Subscribe to vehicle events
RCCP_Events.OnRCCPSpawned += (vehicle) => {
    Debug.Log("Player vehicle spawned: " + vehicle.name);
};

RCCP_Events.OnRCCPAISpawned += (vehicle) => {
    Debug.Log("AI vehicle spawned: " + vehicle.name);
};

RCCP_Events.OnRCCPDestroyed += (vehicle) => {
    Debug.Log("Vehicle destroyed: " + vehicle.name);
};

RCCP_Events.OnVehicleChanged += () => {
    Debug.Log("Active player vehicle changed");
};

RCCP_Events.OnVehicleChangedToVehicle += (vehicle) => {
    Debug.Log("Switched to: " + vehicle.name);
};

RCCP_Events.OnRCCPCollision += (vehicle, collision) => {
    Debug.Log("Collision: " + collision.relativeVelocity.magnitude);
};

Managing All Vehicles

Access the complete vehicle list for gameplay logic:


// Iterate all vehicles
foreach (RCCP_CarController car in RCCP_SceneManager.Instance.allVehicles) {
    Debug.Log(car.name + " speed: " + car.speed);
}

// Count vehicles
int totalCars = RCCP_SceneManager.Instance.allVehicles.Count;

Behavior Presets at Runtime

Switch the global driving behavior preset, which affects steering response, stability aids, and drift settings for all vehicles:


// Switch by name
RCCP.SetBehavior("Drift");

// Switch by index
RCCP.SetBehavior(0);  // First behavior preset

// Get behavior by name
int index = RCCP.GetBehaviorIndexByName("Race");

Terrain Data

RCCP_SceneManager automatically collects terrain data from the scene for ground material detection. The wheel colliders use this data to determine which surface material the tires are on, affecting friction, audio, and particles.

Next Steps