Scene Manager
Table of Contents
- Scene Manager
- Adding the Scene Manager to Your Scene
- Key Properties
- Vehicle Registration
- Registering a Vehicle
- De-Registering a Vehicle
- Automatic Registration
- Transport (Teleport)
- Overloads
- What Happens During Transport
- Example: Respawn at a Checkpoint
- Terrain Caching
- How It Works
- Relevant Properties
- Multithreading Support
- Runtime Settings Applied on Awake
- Events Fired by the Scene Manager
- Example: Listen for Vehicle Changes
- Additional Methods
- Common Issues
- Camera not following the vehicle
- UI not showing
- Vehicle not responding to input
- Multiple vehicles but wrong one is controlled
- Terrain surface detection not working
- Next Steps
The RCCP_SceneManager is a singleton component that acts as the central hub for all RCCP vehicles at runtime. It tracks every vehicle in the scene, manages the active player vehicle, connects the camera and UI automatically, caches terrain data for surface detection, and applies global runtime settings such as fixed timestep and frame rate overrides.
You do not need to interact with RCCP_SceneManager directly in most cases. The static helper class RCCP wraps its methods so you can call RCCP.RegisterPlayerVehicle(), RCCP.Transport(), and other convenience methods from anywhere in your code.
Adding the Scene Manager to Your Scene
Menu path: Tools > BoneCracker Games > Realistic Car Controller Pro > Create > Scene Managers > Add Scene Manager
If you forget to add it manually, RCCP_SceneManager will auto-create itself at runtime the first time any RCCP system accesses RCCP_SceneManager.Instance. This is because it inherits from RCCP_Singleton, which creates a new GameObject automatically when the singleton is first requested.
That said, it is good practice to place the Scene Manager in your scene ahead of time so you can configure its Inspector properties (such as registerLastVehicleAsPlayer) before entering Play mode.
Key Properties
| Property | Type | Default | Description |
|---|---|---|---|
activePlayerVehicle | RCCP_CarController | null | The vehicle currently receiving player input. Set via registration methods. |
activePlayerCamera | RCCP_Camera | null | The RCCP camera following the player vehicle. Auto-assigned when an RCCP camera spawns. |
activePlayerCanvas | RCCP_UIManager | null | The UI manager displaying dashboard gauges, buttons, etc. Auto-assigned when the UI spawns. |
activeMainCamera | Camera | null | Unity's Camera.main reference, updated every frame. |
allVehicles | List | empty | Every RCCP vehicle in the scene, including AI vehicles. Vehicles are added on spawn and removed on destroy. |
registerLastVehicleAsPlayer | bool | true | When enabled, any newly spawned RCCP vehicle is automatically registered as the player vehicle. |
disableUIWhenNoPlayerVehicle | bool | false | When enabled, the UI canvas is hidden whenever there is no active player vehicle. |
Vehicle Registration
Registering a vehicle tells the Scene Manager "this is the player's car." The camera and UI automatically switch to the registered vehicle.
Registering a Vehicle
Use the static RCCP class from any script:
// Register a vehicle as the player vehicle
RCCP.RegisterPlayerVehicle(myVehicle);
// Register with controllable state (true = player can drive it)
RCCP.RegisterPlayerVehicle(myVehicle, true);
// Register with controllable state and engine state
RCCP.RegisterPlayerVehicle(myVehicle, true, true);
| Overload | Parameters | Behavior |
|---|---|---|
RegisterPlayerVehicle(vehicle) | Vehicle only | Sets the vehicle as active. Camera follows it. |
RegisterPlayerVehicle(vehicle, isControllable) | Vehicle + controllable flag | Same as above, plus enables or disables player input on the vehicle. |
RegisterPlayerVehicle(vehicle, isControllable, engineState) | Vehicle + controllable + engine | Same as above, plus starts or stops the engine. |
When a vehicle is registered, the following happens automatically:
activePlayerVehicleis set to the new vehicle.- If an RCCP camera exists, it calls
SetTarget()to follow the new vehicle. - On the next frame, the
OnVehicleChangedandOnVehicleChangedToVehicleevents fire (see API Reference for event details).
De-Registering a Vehicle
RCCP.DeRegisterPlayerVehicle();
This disables player control on the current vehicle, sets activePlayerVehicle to null, and tells the camera to remove its target.
Automatic Registration
If registerLastVehicleAsPlayer is enabled (the default), every vehicle that spawns via RCCP.SpawnRCC() or is already in the scene will be registered automatically. The last vehicle to spawn becomes the player vehicle.
If you are managing multiple vehicles and want manual control over which one the player drives, set registerLastVehicleAsPlayer to false and call RCCP.RegisterPlayerVehicle() yourself.
Transport (Teleport)
Transport instantly moves a vehicle to a new position and rotation. This is useful for respawning after a crash, moving to a checkpoint, or switching between gameplay areas.
Overloads
// Teleport the active player vehicle
RCCP.Transport(newPosition, newRotation);
// Teleport a specific vehicle
RCCP.Transport(targetVehicle, newPosition, newRotation);
// Teleport a specific vehicle, with optional velocity reset
RCCP.Transport(targetVehicle, newPosition, newRotation, resetVelocity);
| Overload | Parameters | Description |
|---|---|---|
Transport(position, rotation) | Position + Rotation | Teleports the active player vehicle. Always resets velocity. |
Transport(vehicle, position, rotation) | Vehicle + Position + Rotation | Teleports a specific vehicle. Always resets velocity. |
Transport(vehicle, position, rotation, resetVelocity) | Vehicle + Position + Rotation + bool | Teleports a specific vehicle. If resetVelocity is false, the vehicle keeps its current speed. |
What Happens During Transport
- Rigidbody interpolation is temporarily set to
Noneto prevent visual glitches. - Linear and angular velocity are zeroed (unless
resetVelocityis false). - The vehicle is moved via
Rigidbody.MovePosition()andRigidbody.MoveRotation(). - All wheel collider motor torques are reset to zero.
- If the vehicle has a connected trailer, the trailer is moved along with it, maintaining its relative offset.
Physics.SyncTransforms()is called to ensure the physics engine recognizes the new position immediately.
Example: Respawn at a Checkpoint
public Transform respawnPoint;
public void RespawnPlayer() {
RCCP.Transport(respawnPoint.position, respawnPoint.rotation);
}
Terrain Caching
RCCP_SceneManager caches Unity Terrain splatmap data at startup so that wheel colliders can look up ground materials efficiently at runtime. This is how the system knows whether a wheel is on grass, asphalt, gravel, or any other surface defined in your Ground Materials setup.
How It Works
- On
Start(), the Scene Manager callsGetAllTerrains()as a coroutine. - It collects all active terrains via
Terrain.activeTerrains. - For each terrain, it caches:
- The
TerrainDatareference - The terrain collider's physics material
- The alphamap dimensions
- The full splatmap data array (
GetAlphamaps) - The number of texture layers
- Once complete, the
terrainsInitializedflag is set to true.
Relevant Properties
| Property | Type | Description |
|---|---|---|
allTerrains | Terrain[] | Array of all Unity Terrains found in the scene. |
terrains | Terrains[] | Cached terrain data (splatmap, alphamap dimensions, physics material) for each terrain. |
terrainsInitialized | bool | True once all terrain data has been cached and is ready for ground material queries. |
If your scene does not use Unity Terrains (for example, you use mesh-based roads only), these properties will remain empty and the flag will stay false. Ground material detection will then rely on physics material assignments on your mesh colliders instead.
Multithreading Support
RCCP_SceneManager checks at startup whether the current platform supports async/await operations. Some platforms (such as WebGL) do not support multithreading.
RCCP_SceneManager.multithreadingSupported // static bool
The check works by attempting to run a trivial Task.Run() call. If it completes within one second, multithreadingSupported is set to true. If it fails or times out, it is set to false and RCCP falls back to synchronous methods.
This flag is used primarily by the Damage System for async mesh deformation and repair operations.
Note: Multithreading can be disabled globally in RCCP Settings by unchecking the multithreading toggle, regardless of platform support.
Runtime Settings Applied on Awake
When RCCP_SceneManager initializes, it reads several values from RCCP_Settings and applies them to the Unity runtime:
| Setting | Condition | Effect |
|---|---|---|
| Fixed Timestep | overrideFixedTimeStep is true | Sets Time.fixedDeltaTime to the configured fixedTimeStep value (default 0.02). |
| Frame Rate | overrideFPS is true | Sets Application.targetFrameRate to the configured maxFPS value (default 120). |
| Telemetry UI | useTelemetry is true | Instantiates the telemetry overlay prefab for real-time vehicle data display. |
| Input Rebinds | autoSaveLoadInputRebind is true | Loads saved input rebind overrides from PlayerPrefs on Awake, and saves them on disable. |
These overrides are applied once during Awake. If you need different values at runtime, you can modify Time.fixedDeltaTime or Application.targetFrameRate directly after the Scene Manager initializes.
Events Fired by the Scene Manager
The Scene Manager monitors the active player vehicle each frame and fires events when it changes:
| Event | Signature | When It Fires |
|---|---|---|
RCCP_Events.OnVehicleChanged | void() | A different vehicle becomes the active player vehicle. |
RCCP_Events.OnVehicleChangedToVehicle | void(RCCP_CarController) | Same as above, but passes the new vehicle as a parameter. |
Example: Listen for Vehicle Changes
void OnEnable() {
RCCP_Events.OnVehicleChanged += OnPlayerVehicleChanged;
}
void OnDisable() {
RCCP_Events.OnVehicleChanged -= OnPlayerVehicleChanged;
}
void OnPlayerVehicleChanged() {
Debug.Log("Player switched to: " +
RCCP_SceneManager.Instance.activePlayerVehicle.name);
}
The Scene Manager also listens to these internal events to track vehicles:
| Event | Purpose |
|---|---|
OnRCCPSpawned | Adds the vehicle to allVehicles. Registers as player if registerLastVehicleAsPlayer is true. |
OnRCCPAISpawned | Adds the AI vehicle to allVehicles. |
OnRCCPDestroyed | Removes the vehicle from allVehicles. |
OnRCCPAIDestroyed | Removes the AI vehicle from allVehicles. |
OnRCCPCameraSpawned | Sets activePlayerCamera. If a player vehicle already exists, sets it as the camera target. |
OnRCCPUISpawned | Sets activePlayerCanvas. |
Additional Methods
| Method | Parameters | Description |
|---|---|---|
SetBehavior(int behaviorIndex) | Index of the behavior preset | Activates behavior override mode and applies the preset at the given index from the behavior types array in RCCP_Settings. |
SetMobileController(MobileController type) | TouchScreen, Gyro, SteeringWheel, or Joystick | Switches the active mobile controller type. See Mobile Input. |
ChangeCamera() | None | Cycles to the next camera mode on the active RCCP camera. See Camera System. |
Common Issues
Camera not following the vehicle
- Make sure an
RCCP_Cameracomponent exists in the scene, or that auto-creation of the camera is enabled in RCCP Settings. - If you manually placed the camera and the vehicle in the scene, the camera should auto-target the vehicle once
OnRCCPCameraSpawnedfires. If the vehicle spawns before the camera, the Scene Manager handles this by setting the target when the camera spawns.
UI not showing
- Check that
disableUIWhenNoPlayerVehicleis not hiding the canvas. If this is enabled and no vehicle is registered, the UI will be hidden. - Ensure an
RCCP_UIManagerprefab is in the scene or configured for auto-creation in RCCP Settings.
Vehicle not responding to input
- Confirm the vehicle is registered as the player vehicle. Call
RCCP.RegisterPlayerVehicle(vehicle, true)to register it with input enabled. - If
registerLastVehicleAsPlayeris enabled, the last spawned vehicle automatically becomes the player vehicle. Earlier vehicles lose player status.
Multiple vehicles but wrong one is controlled
- Set
registerLastVehicleAsPlayerto false in the Scene Manager Inspector. - Manually call
RCCP.RegisterPlayerVehicle()on the vehicle you want the player to control.
Terrain surface detection not working
- Make sure your scene uses Unity Terrain objects (not just mesh colliders).
- Check that
terrainsInitializedis true after the first few frames. - If using mesh-based roads, assign appropriate physics materials to the mesh colliders and configure them in Ground Materials.
Next Steps
- API Reference -- Full list of public methods in the RCCP static class
- Camera System -- Camera modes, setup, and configuration
Support: bonecrackergames@gmail.com | www.bonecrackergames.com
Need help? See Troubleshooting