Scene Management
Table of Contents
- Scene Management
- Overview
- RCCP_SceneManager Properties
- Setting Up a Scene
- Spawning Vehicles
- Via Script (Recommended)
- Via Scene Placement
- Registering and Deregistering Players
- Register
- Deregister
- Switch Between Vehicles
- Teleporting Vehicles
- Vehicle Events
- Managing All Vehicles
- Behavior Presets at Runtime
- Terrain Data
- Next Steps
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
| Property | Type | Description |
|---|---|---|
activePlayerVehicle | RCCP_CarController | The current player-controlled vehicle |
activePlayerCamera | RCCP_Camera | The active camera following the player |
activePlayerCanvas | RCCP_UIManager | The active UI canvas |
activeMainCamera | Camera | The Unity main camera |
allVehicles | List<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:
- RCCP_SceneManager — Vehicle registry singleton
- RCCP_SkidmarksManager — Manages tire marks on the ground
- RCCP_Camera — Camera system (optional but recommended)
- 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
- 12_Settings.md — Global settings and behavior configuration
- 13_API.md — Complete API reference