On this page
Scripting

Events System

RCC_Events is a static class of C# events that RCC raises when vehicles spawn, collide or are destroyed, when AI and cameras are enabled, and when input actions fire. This page lists every event, who raises it and when.

Quick Start

  1. Create a script and add it to any GameObject in your scene.
  2. Subscribe in OnEnable with +=.
  3. Unsubscribe in OnDisable with -=, using the same method.
  4. Match each handler's parameters to the event's signature (see the table below).
C#
using UnityEngine;

public class MyRCCEventListener : MonoBehaviour {

    private void OnEnable() {

        RCC_Events.OnRCCPlayerSpawned += OnVehicleSpawned;
        RCC_Events.OnRCCPlayerCollision += OnPlayerCollision;
        RCC_Events.OnGearShiftUp += OnGearUpPressed;

    }

    private void OnDisable() {

        RCC_Events.OnRCCPlayerSpawned -= OnVehicleSpawned;
        RCC_Events.OnRCCPlayerCollision -= OnPlayerCollision;
        RCC_Events.OnGearShiftUp -= OnGearUpPressed;

    }

    private void OnVehicleSpawned(RCC_CarControllerV4 vehicle) {

        Debug.Log("Vehicle spawned: " + vehicle.name);

    }

    private void OnPlayerCollision(RCC_CarControllerV4 vehicle, Collision collision) {

        Debug.Log(vehicle.name + " hit " + collision.gameObject.name + " at " + collision.relativeVelocity.magnitude.ToString("F1") + " m/s");

    }

    private void OnGearUpPressed() {

        Debug.Log("Gear up pressed");

    }

}

All Events

Each group of events, the RCC script that raises it, and the RCC scripts that already listen to it.
Event Signature Raised by When
OnRCCPlayerSpawned (RCC_CarControllerV4 RCC) RCC_CarControllerV4 At the end of the frame any non-AI vehicle is enabled. Again on every re-enable.
OnRCCPlayerDestroyed (RCC_CarControllerV4 RCC) RCC_CarControllerV4 In OnDestroy of every vehicle, AI included.
OnRCCPlayerCollision (RCC_CarControllerV4 RCC, Collision collision) RCC_CarControllerV4 OnCollisionEnter of the active player vehicle, relative velocity ≥ 5 m/s.
OnRCCAISpawned (RCC_AICarController RCCAI) RCC_AICarController The AI component's OnEnable.
OnRCCAIDestroyed (RCC_AICarController RCCAI) RCC_AICarController The AI component's OnDisable (also runs when it is destroyed).
OnBCGCameraSpawned (GameObject BCGCamera) RCC_Camera Every RCC_Camera OnEnable. Passes the camera's GameObject.
OnBehaviorChanged () RCC_SceneManager RCC.SetBehavior(int) or RCC_SceneManager.SetBehavior(int).
OnVehicleChanged () RCC_SceneManager Scene Manager Update sees a different active player vehicle.
OnStartStopEngine () RCC_InputManager Start / Stop Engine input pressed.
OnLowBeamHeadlights () RCC_InputManager Low Beam input pressed.
OnHighBeamHeadlights () RCC_InputManager High Beam input pressed.
OnChangeCamera () RCC_InputManager Change Camera input pressed.
OnIndicatorLeft () RCC_InputManager Indicator Left input pressed.
OnIndicatorRight () RCC_InputManager Indicator Right input pressed.
OnIndicatorHazard () RCC_InputManager Hazard input pressed.
OnInteriorlights () RCC_InputManager Interior Light input pressed.
OnGearShiftUp () RCC_InputManager Gear Up input pressed.
OnGearShiftDown () RCC_InputManager Gear Down input pressed.
OnNGear (bool state) RCC_InputManager Neutral input: true on press, false on release.
OnSlowMotion (bool state) RCC_InputManager, RCC_UI_DashboardButton Slow Motion input: true on press, false on release. Also the dashboard Slow Mo button (toggles).
OnRecord () RCC_InputManager Record input pressed.
OnReplay () RCC_InputManager Replay input pressed.
OnLookBack (bool state) RCC_InputManager Look Back input: true on press, false on release.
OnTrailerDetach () RCC_InputManager Trailer Detach input pressed.
OnPlayerEnteredVehicle (RCC_EnterExitPlayer player, RCC_EnterExitVehicle vehicle) RCC_EnterExitPlayer Character gets in, after the vehicle is registered as the player vehicle. Enter-Exit addon only.
OnPlayerExitedVehicle (RCC_EnterExitPlayer player, RCC_EnterExitVehicle vehicle) RCC_EnterExitPlayer Character gets out, after the vehicle is de-registered. Enter-Exit addon only.

Every event has a matching public Event_On… method on RCC_Events that raises it, for example RCC_Events.Event_OnRCCPlayerSpawned(vehicle).

Timing Notes

Vehicle events

A vehicle's events over its life: spawn events arrive at the end of the frame, OnVehicleChanged in the next Scene Manager Update, collision events only for the active player vehicle, and the destroyed event only when the vehicle is destroyed.
  • OnRCCPlayerSpawned fires for any vehicle that is not externally controlled, not only the player's. AI vehicles and remote Photon vehicles are skipped.
  • The Scene Manager listens to it. If Register Last Spawned Vehicle As Player Vehicle is on (the default), it registers that vehicle as the player vehicle. No "Player" tag is involved.
  • It is not raised immediately. Code that runs right after spawning a vehicle won't see it yet.
  • OnRCCPlayerDestroyed is not raised by RCC.DeRegisterPlayerVehicle() or by disabling a vehicle. It is raised only when a vehicle is destroyed, including during scene unload.
  • OnRCCPlayerCollision only fires for the vehicle in RCC_SceneManager.activePlayerVehicle, on contacts with a relative velocity of 5 m/s or more.

Scene events

  • OnVehicleChanged has no parameter. Read RCC_SceneManager.Instance.activePlayerVehicle in your handler.
  • It is detected in the Scene Manager's Update, so it can arrive one frame after the change. It also fires for the first player vehicle.
  • It does not fire when the player vehicle is cleared.
  • RCC.SetBehavior(int) turns the global behavior preset on before raising OnBehaviorChanged. See Behavior Presets.

Input events

  • They come from the Input System actions (keyboard, gamepad, wheel). See Input System for the bindings.
  • OnGearShiftUp / OnGearShiftDown fire only on gear input. Automatic gear changes, the dashboard gear buttons and GearShiftUp() / GearShiftDown() calls do not raise them.
  • Dashboard UI buttons act on the vehicle directly and do not raise input events. The Slow Mo button is the exception.

Changed in V6: the dashboard Slow Mo button raises OnSlowMotion. The Scene Manager restores the time scale the game was running at, and slow motion no longer carries into the next scene.

Enter-Exit events

OnPlayerEnteredVehicle and OnPlayerExitedVehicle exist only when the BCG_ENTEREXIT define is set, which importing the Enter-Exit addon does. Wrap any code that uses them in #if BCG_ENTEREXIT. See Addon Packages.

Pitfalls

  • Always unsubscribe. The events are static. A handler you never remove keeps running after its object is destroyed and throws errors. Subscribing twice runs it twice.
  • Late subscribers miss past events. If a vehicle spawned before your script was enabled, you won't get OnRCCPlayerSpawned for it. Read RCC_SceneManager.Instance.activePlayerVehicle in OnEnable as well.
  • Nothing fires the same frame. OnRCCPlayerSpawned comes at the end of the frame, and OnVehicleChanged in the next Scene Manager Update.
  • RCC_SceneManager.Instance creates a Scene Manager if the scene has none. Don't read it in OnDisable or OnDestroy. Unsubscribing never needs it.

See Also

BoneCracker Games · Realistic Car ControllerBack to top ↑
Document details

Generated from: 24_EventsSystem.md
Date: 2026-09-24 01:26
© 2014 - 2026 BoneCracker Games — Realistic Car Controller V6.0.0