API Reference
Goal: find the C# method for an action, for example to spawn a vehicle, request a repair or start a replay. This chapter is a lookup reference for readers who know how to attach a C# script in Unity.
This chapter lists all public members of the RCCP class and all events of RCCP_Events. Other RCCP components have more public members that this chapter does not list.
For setup in the Inspector only, return to the guide. To drive inputs from a script, start with Controlling Vehicles from Code.
Find the action you need
| I want my script to… | Section |
|---|---|
| Create a vehicle or choose the player vehicle | Spawning and registering |
| Enable controls or start the engine | Controlling a vehicle |
| Change transmission or driver assists | Gearbox and driver assists |
| Change camera or take a photo | Camera and photo mode |
| Move a vehicle to a checkpoint | Transport and skidmarks |
| Repair a vehicle | Damage and repair |
| Record and play back one vehicle | Per-vehicle recording |
| Replay a drive | Instant replay |
| Select a driving preset | Behavior presets |
| Route vehicle audio or change its volume | Audio routing |
| React when something occurs | Events |
| Read or configure wheels, or upgrade wheel data | Wheel API |
How to read a signature
A signature gives the name of a method and the values that the method needs. For example, SetEngine(RCCP_CarController vehicle, bool engineState) needs a vehicle reference and a true or false value. True starts the engine. False stops the engine.
- Call the methods through
RCCPin your own method, for exampleRCCP.SetEngine(vehicle, true);. vehicleis a reference to the vehicle that you control.vehicleis not a built-in variable.- Returns gives the value that the method returns.
voidmeans that there is no return value.boolmeans true or false. - An overload is a different version of the same method with different arguments. Use the row that agrees with your data.
- An event is a notification that your script can receive, for example when a vehicle spawns.
Check: before you use a row, know the target object, the arguments and if you must examine the result. Read the notes below each table for necessary modules and timing.
How the facade behaves
RCCP is the main API entry point (a facade). RCCP is a static class in the BoneCrackerGames namespace. Add using BoneCrackerGames; to your script. Core runtime code has no assembly definition and compiles into Assembly-CSharp. Only the installer has an assembly definition, the editor assembly BoneCrackerGames.RCCPro.Installer.
The API examines vehicle references and necessary components. If a reference or component is missing, many calls log a warning and do nothing. Read that warning before you change settings. SpawnRCC logs an error if the prefab is missing. IsRepaired logs nothing and returns true if there is nothing to repair.
Spawn and register vehicles
| Signature | Returns |
|---|---|
SpawnRCC(RCCP_CarController vehiclePrefab, Vector3 position, Quaternion rotation, bool registerAsPlayerVehicle, bool isControllable, bool isEngineRunning) |
RCCP_CarController |
RegisterPlayerVehicle(RCCP_CarController vehicle) |
void |
RegisterPlayerVehicle(RCCP_CarController vehicle, bool isControllable) |
void |
RegisterPlayerVehicle(RCCP_CarController vehicle, bool isControllable, bool engineState) |
void |
DeRegisterPlayerVehicle() |
void |
If the prefab is null, SpawnRCC logs an error and returns null. SpawnRCC sets the "never auto-register" flag before it instantiates the prefab. RCCP vehicle prefabs are active, and Unity runs OnEnable inside Instantiate. Thus registerAsPlayerVehicle: false applies to active and inactive prefabs.
Control a vehicle
| Signature | Returns |
|---|---|
SetControl(RCCP_CarController vehicle, bool isControllable) |
void |
SetExternalControl(RCCP_CarController vehicle, bool isExternal) |
void |
SetEngine(RCCP_CarController vehicle, bool engineState) |
void |
SetMobileController(RCCP_Settings.MobileController mobileController) |
void |
The values of RCCP_Settings.MobileController are TouchScreen, Gyro, SteeringWheel and Joystick.
Gearbox and driver assists
| Signature | Returns |
|---|---|
SetAutomaticGear(RCCP_CarController vehicle, bool state) |
void |
SetAutomaticGear(RCCP_CarController vehicle, RCCP_Gearbox.TransmissionType transmissionType) |
void |
SetHillStartAssist(RCCP_CarController vehicle, bool state) |
void |
SetCruiseControl(RCCP_CarController vehicle, bool state) |
void |
SetCruiseControl(RCCP_CarController vehicle, bool state, float targetSpeed) |
void |
The values of RCCP_Gearbox.TransmissionType are Manual, Automatic and Automatic_DNRP. The bool overload of SetAutomaticGear selects Automatic for true and Manual for false. That overload cannot set Automatic_DNRP. For Automatic_DNRP, use the enum overload.
targetSpeed is in km/h. The three assist methods need the Inputs component of the vehicle. The gearbox methods need its Gearbox.
Camera, photo mode and the crash cinematic
| Signature | Returns |
|---|---|
ChangeCamera() |
void |
EnterPhotoMode() |
void |
ExitPhotoMode() |
void |
CapturePhoto() |
string |
SetPhotoCameraMode(RCCP_PhotoMode.PhotoCameraMode mode) |
void |
CyclePhotoCameraMode() |
void |
SetPhotoFieldOfView(float fieldOfView) |
void |
TriggerCrashCam() |
bool |
CancelCrashCam() |
void |
IsCrashCamActive |
bool (property) |
The values of RCCP_PhotoMode.PhotoCameraMode are Orbit, FreeCam and AutoOrbit. CyclePhotoCameraMode moves through the modes in that sequence. SetPhotoFieldOfView takes degrees. Photo mode limits the value to its minimum and maximum field of view.
CapturePhoto requests a screenshot in Application.persistentDataPath/Photos and returns its absolute path. The returned path does not confirm that the save is complete. On Android, the save runs in the background and can take several seconds.
When photo mode stops or is disabled, photo mode restores the time scale and audio state that it captured. If the game was paused before photo mode, the game stays paused.
TriggerCrashCam starts the cinematic on the active player vehicle, with the shot point in front of the vehicle. An explicit call ignores the delta-v and cooldown limits. The call returns false if the active player vehicle or the player camera is missing. The call also returns false while a crash cinematic or a replay runs.
The call also returns false if no clear camera angle exists, or if Let a crash take this camera is disabled. That option is disabled on the shipped RCCP_Camera prefab.
You can call CancelCrashCam safely when no cinematic runs. IsCrashCamActive does not create the director if no director exists.
Call CancelCrashCam() before a pause menu captures or changes Time.timeScale. The call immediately stops the cinematic or its recovery. The call restores the camera, time and audio state that the cinematic controls. If a different system changes the time scale, the crash camera releases time control and keeps the new time scale.
Transport and skidmarks
| Signature | Returns |
|---|---|
Transport(Vector3 position, Quaternion rotation) |
void |
Transport(RCCP_CarController vehicle, Vector3 position, Quaternion rotation) |
void |
Transport(RCCP_CarController vehicle, Vector3 position, Quaternion rotation, bool resetVelocity) |
void |
CleanSkidmarks() |
void |
CleanSkidmarks(int index) |
void |
Transport(position, rotation) moves the active player vehicle. The overloads with a vehicle argument move that vehicle.
Each Transport call resets the wheel solver state, also with resetVelocity: false. See reset timing and scope.
Damage and repair
| Signature | Returns |
|---|---|
Repair(RCCP_CarController carController) |
void |
Repair() |
void |
IsRepaired(RCCP_CarController carController) |
bool |
A repair is a request, not an immediate change of state. Repair sets repairNow, and the damage component reads repairNow in its next update. If the vehicle has a deformation solver, the vehicle goes back to its shape over several frames.
Poll IsRepaired. Do not read the repaired flag directly, because the flag is not true in the frame of the request. IsRepaired returns true for a null vehicle and for a vehicle without a damage component. True means that no repair is pending. If you deactivate a vehicle before IsRepaired returns true, the vehicle keeps its damage. A disabled component does not update.
Per-vehicle recording
The per-vehicle recorder records a clip on one vehicle and plays the clip on the same vehicle.
| Signature | Returns |
|---|---|
StartStopRecord(RCCP_CarController vehicle) |
void |
StartStopReplay(RCCP_CarController vehicle) |
void |
StartStopReplay(RCCP_CarController vehicle, RCCP_Recorder.RecordedClip recordedClip) |
void |
StopRecordReplay(RCCP_CarController vehicle) |
void |
These calls need a vehicle with an Other Addons manager and a Recorder. Use the module tools of the vehicle to add the Recorder before you call these methods.
Instant replay
The replay director is a scene component and is separate from the per-vehicle recorder. Add a director with Tools > BoneCracker Games > Realistic Car Controller Pro 2 > Add to Scene > Replay Director.
The replay director resets the wheel solver state at playback start, live resume, direction changes, seeks and replay exit. Recorder playback also resets the wheel state when it moves the vehicle to the first recorded pose. See wheel reset behavior.
| Signature | Returns |
|---|---|
StartReplay() |
RCCP_ReplayStartResult |
StopReplay() |
void |
IsReplayActive |
bool (property) |
ResumeFromReplay() |
bool |
CanResumeReplay |
bool (property) |
SaveReplayClip(string name) |
bool |
PlayReplayClip(RCCP_ReplayClip clip) |
RCCP_ReplayStartResult |
ListReplayClips() |
string[] |
If the scene has no director, StartReplay and PlayReplayClip log a warning and return NoDirector. SaveReplayClip saves clips in persistentDataPath/RCCP_Replays with the extension .rccpreplay. In the file name, _ replaces each character that the file system does not accept. A save never overwrites a clip that exists.
ListReplayClips returns full paths, newest first, and does not need a director. Load a saved clip with RCCP_ReplayClipIO.Load(string path, out RCCP_ReplayClip clip, out string error). Then give the clip to PlayReplayClip.
ResumeFromReplay stops the replay at its current moment, and the live drive continues from that moment. The call returns false in these conditions:
- No replay runs.
- Allow Resume on the director is disabled.
- A saved clip plays.
- The number of resumes reached the Max Resumes limit.
CanResumeReplay is true only when none of these conditions apply.
RCCP_ReplayStartResult has eight values:
| Value | Meaning |
|---|---|
Started |
The replay runs. |
NoDirector |
The scene has no replay director. |
Multiplayer |
Replays are not available in multiplayer sessions. |
BufferTooShort |
The recorded or playable time is less than one second. |
AlreadyActive |
A replay runs already. |
PhotoModeActive |
Photo mode is active. Stop photo mode first. |
LegacyRecorderBusy |
A per-vehicle recorder on a recorded vehicle records or plays. |
Failed |
A different cause. Read RCCP_ReplayDirector.Current.LastStartMessage for the cause. |
LastStartMessage also gives details for results other than Failed. For example, it names the clip vehicles that the director skipped. The director skips a clip vehicle if the scene has no vehicle for it and Clip Vehicle Prefabs has no matching prefab.
Behavior presets
| Signature | Returns |
|---|---|
SetBehavior(int behaviorIndex) |
void |
SetBehavior(string behaviorName) |
void |
ClearBehavior() |
void |
GetBehaviorIndexByName(string behaviorName) |
int |
GetBehaviorByName(string behaviorName) |
RCCP_Settings.BehaviorType |
The index is an index into RCCP_Settings.behaviorTypes. Name lookups are not case-sensitive. If no name agrees, GetBehaviorIndexByName returns -1 and GetBehaviorByName returns null. The string overload of SetBehavior then logs a warning and does nothing.
ClearBehavior disables overrideBehavior, and global preset changes then do not reach vehicles. ClearBehavior does not restore the values that a preset wrote. Vehicles keep the values that they have.
For wheel curve changes from presets, see the supported wheel hooks.
Audio routing
| Signature | Returns |
|---|---|
SetAudioOutputBus(AudioMixerGroup hostGroup) |
bool |
ClearAudioOutputBus() |
void |
SetAudioVolume(RCCP_AudioCategory category, float volume01) |
bool |
ClearAudioVolume(RCCP_AudioCategory category) |
void |
Call SetAudioOutputBus one time at startup with a group from your mixer. All RCCP vehicle audio then goes through that group. The RCCP mixer goes below the group that you supply. Thus the exposed pitch parameter that the crash cinematic controls continues to operate. SetAudioOutputBus returns false if RCCP Settings has no audio mixer group, or if the group is in the RCCP mixer.
Give null to send the audio directly to the audio listener. ClearAudioOutputBus restores the original output of the RCCP mixer.
SetAudioVolume sets the volume of one sound group (Engine, Tires, Impacts or Other). The volume applies to vehicles that use the mixer group from RCCP Settings. A value of 1 is the authored level, and 0 is silence. The method returns false and changes nothing in these conditions:
- RCCP Settings has no mixer.
- The group for that category in RCCP Settings is empty or in a different mixer.
- The mixer has no parameter for that category.
Unity also accepts mixer writes only in Play Mode. ClearAudioVolume sets the group back to its authored volume. In the Editor, RCCP clears volumes set during Play Mode when Play Mode stops.
Events
The events in RCCP_Events are static. Static events stay after a scene load and after your objects are destroyed. Unsubscribe in OnDisable. If a subscriber is destroyed without an unsubscribe, the event continues to call its handler. A handler that uses the destroyed object can throw an exception.
using BoneCrackerGames;
void OnEnable() {
RCCP_Events.OnRCCPSpawned += VehicleSpawned;
}
void OnDisable() {
RCCP_Events.OnRCCPSpawned -= VehicleSpawned;
}
void VehicleSpawned(RCCP_CarController vehicle) { }
Lifecycle
| Event | Handler signature |
|---|---|
OnRCCPSpawned |
(RCCP_CarController rccp) |
OnRCCPDestroyed |
(RCCP_CarController rccp) |
OnRCCPAISpawned |
(RCCP_CarController rccp) |
OnRCCPAIDestroyed |
(RCCP_CarController rccp) |
OnRCCPCameraSpawned |
(RCCP_Camera cam) |
OnRCCPUISpawned |
(RCCP_UIManager UI) |
OnRCCPUIDestroyed |
(RCCP_UIManager UI) |
OnVehicleChanged |
() |
OnVehicleChangedToVehicle |
(RCCP_CarController carController) |
OnBehaviorChanged |
() |
OnRCCPUIInformer |
(string text) |
OnRCCPDestroyed and OnRCCPAIDestroyed occur when a vehicle is destroyed or disabled.
Collisions and damage
| Event | Handler signature |
|---|---|
OnRCCPCollision |
(RCCP_CarController rccp, Collision collision) |
OnRCCPCollisionEnter |
(RCCP_CarController rccp, Collision collision) |
OnRCCPImpact |
(RCCP_CarController rccp, float impulse) |
OnRCCPDamaged |
(RCCP_CarController rccp) |
OnRCCPRepaired |
(RCCP_CarController rccp) |
OnRCCPZoneDamaged |
(RCCP_CarController rccp, RCCP_DamageZone zone, float health01) |
OnRCCPPartDetached |
(RCCP_CarController rccp, RCCP_DetachablePart part) |
OnRCCPWheelDetached |
(RCCP_CarController rccp, RCCP_WheelCollider wheel) |
OnRCCPLightBroken |
(RCCP_CarController rccp, RCCP_Light light) |
OnRCCPCaughtFire |
(RCCP_CarController rccp) |
OnRCCPWheelDetached gives the wheel facade. Use its public readouts to examine the wheel.
Three of these events look the same, but they are different:
| Event | When |
|---|---|
OnRCCPCollision |
Each contact, also collision stay. Damage and particles use this event. |
OnRCCPCollisionEnter |
One time for each collision enter, before RCCP applies damage. Shows the start of an impact. |
OnRCCPImpact |
Limited by a cooldown for each vehicle and a minimum impulse. Use this event for gameplay, for example sound stingers, score and UI shake. |
The values of RCCP_DamageZone are Front, Rear, Left and Right. health01 is from 0 to 1, and 1 is intact. OnRCCPCaughtFire needs the damage mechanics addon on the vehicle.
Fuel, boost and cinematics
| Event | Handler signature |
|---|---|
OnRCCPFuelEmpty |
(RCCP_CarController rccp) |
OnRCCPNosEmpty |
(RCCP_CarController rccp) |
OnRCCPReplayStarted |
() |
OnRCCPReplayEnded |
() |
OnRCCPReplayResumed |
() |
OnRCCPCrashCamStarted |
(RCCP_CarController rccp, Vector3 impactPoint) |
OnRCCPCrashCamEnded |
(RCCP_CarController rccp) |
OnRCCPFuelEmpty and OnRCCPNosEmpty occur one time. Each event becomes ready again after a refill or regeneration. OnRCCPReplayStarted occurs after the live world is frozen. OnRCCPReplayEnded occurs when a replay ends. StopReplay restores the live world first.
ResumeFromReplay keeps the world at the current moment of the replay. ResumeFromReplay sends OnRCCPReplayResumed immediately before OnRCCPReplayEnded. OnRCCPCrashCamEnded occurs on each exit path, also on a cancel.
Raise events from code
Each event has a related static Event_* method that raises the event, for example Event_OnRCCPSpawned and Event_OnRCCPImpact. RCCP components use these methods to raise events that a different class owns. Do not call these methods from game code. A call sends a notification for an action that did not occur, and the listeners become incorrect.
Optional visual effect access
CarController.Lights.LightCones returns the optional RCCP_LightCones component. CarController.AxleManager.TireDeformation returns the optional BoneCrackerGames.RCCP_TireDeformation component. Examine the owner and the returned component for null. These properties find components that exist. The properties never create components.
RCCP continues to find these components when they are on the vehicle root, the earlier location. RCCP_LightCones.GetOrCreate(car) adds missing beams below Lights. If the vehicle has no Lights manager, GetOrCreate adds the beams below the vehicle.
Call RCCP_FakeShadow.Rebuild() on the component after runtime changes to the vehicle body, its wheels or the shadow shape settings. The method removes the current shadow geometry. The next frame measures the vehicle again and creates the geometry from the current settings.
Common mistakes
| What | Why |
|---|---|
| You read the repaired flag of the damage component directly | The flag is false during all frames of the repair animation. Poll IsRepaired. |
You disable canControl to drive from a script |
canControl also blocks scripted and AI inputs. Keep it enabled and enable externalControl for a scripted driver. To stop an AI, stop its driver or make it request braking. |
You call SetAutomaticGear with a bool to get the DNRP selector |
The bool overload sets only Manual and Automatic. Give the enum. |
You call StartReplay and do not examine the result |
The method returns a result. Seven of its eight values mean that the replay did not start. |
You call the Event_* methods |
These methods raise events. These methods do not receive events. |
Read next
- Scripting Reference: examples that drive a vehicle from code.
- Architecture Reference: the component that owns each function, and the execution order of the events.
- Field Reference: all serialized settings on all components, with defaults and ranges.
- Replay and Recording: what the replay director does, and how to add one before you call it.