NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class VehicleComponent

    Base class for every vehicle subsystem and module: Powertrain, Steering, Brakes, Effects, Sound and the rest. Defines the initialize/update/enable/disable interface and the LOD hooks.

    Inheritance
    object
    VehicleComponent
    Brakes
    Effect
    GroundDetection
    VehicleInputHandler
    ManagerVehicleComponent
    ABSModule
    AerodynamicsModule
    AirSteerModule
    ArcadeModule
    CruiseControlModule
    ESCModule
    FlipOverModule
    FuelModule
    MetricsModule
    ModuleTemplate
    MotorcycleModule
    NOSModule
    RiggingModule
    SpeedLimiterModule
    TCSModule
    TrailerHitchModule
    TrailerModule
    PowertrainComponent
    SoundComponent
    Steering
    Namespace: NWH.VehiclePhysics2
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public abstract class VehicleComponent
    Remarks

    The VC_ prefix marks the virtual methods so they do not read as Unity callbacks. Enabled state and LOD index come from StateSettings and can also be changed at runtime.

    Fields

    state

    Runtime state of this component: enabled flag, initialized flag and LOD index.

    Declaration
    [NonSerialized]
    [Tooltip("Contains info about component's state.")]
    public StateDefinition state
    Field Value
    Type Description
    StateDefinition

    vehicleController

    Parent VehicleController. Set by VC_Initialize(VehicleController).

    Declaration
    [NonSerialized]
    public VehicleController vehicleController
    Field Value
    Type Description
    VehicleController

    Properties

    IsActive

    True when the component is both initialized and enabled. Only active components update.

    Declaration
    public bool IsActive { get; }
    Property Value
    Type Description
    bool

    Methods

    ToggleState()

    Flips the component between enabled and disabled, for UI and script use.

    Declaration
    public virtual void ToggleState()
    Remarks

    Manually toggles state regardless of LOD settings. There is no play-mode check; calling this outside play mode will run VC_Initialize(). The LOD system overrides manual state changes when lodIndex >= 0.

    UpdateLOD()

    Enables or disables the component for the vehicle's current LOD level. Called by the LOD system as camera distance changes.

    Declaration
    public virtual void UpdateLOD()
    Remarks

    Only components with lodIndex >= 0 are LOD controlled. lodIndex = -1 opts out and keeps whatever state was set manually.

    VC_Disable(bool)

    Disables the component and stops its updates.

    Declaration
    public virtual bool VC_Disable(bool calledByParent)
    Parameters
    Type Name Description
    bool calledByParent

    True when called by a parent ManagerVehicleComponent fan-out or the VehicleController enable/disable loop. The LOD system passes false.

    Returns
    Type Description
    bool

    True if successfully disabled, false otherwise

    Remarks

    Refused on a component that is not initialized. Records whether the call came from a parent, which is what VC_Enable checks before a bulk re-enable.

    VC_DrawGizmos()

    Draws component gizmos in the Scene view while the vehicle is selected. Editor only, and only while the component is enabled.

    Declaration
    public virtual void VC_DrawGizmos()

    VC_Enable(bool)

    Enables the component and starts its updates.

    Declaration
    public virtual bool VC_Enable(bool calledByParent)
    Parameters
    Type Name Description
    bool calledByParent

    True when called by a parent ManagerVehicleComponent fan-out or the VehicleController enable/disable loop. The LOD system passes false.

    Returns
    Type Description
    bool

    True if successfully enabled, false otherwise

    Remarks

    Initializes the component first if it is not initialized yet. A parent bulk enable is refused unless the last disable also came from a parent, so it cannot resurrect a component turned off by LOD, by a script, or disabled in StateSettings.

    VC_FixedUpdate(float)

    Fixed-timestep update for forces, torques and other physics work. Called from VehicleController.FixedUpdate(), and only while the component is active.

    Declaration
    public virtual void VC_FixedUpdate(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime

    Time elapsed since last FixedUpdate in seconds

    VC_Initialize()

    One-time setup, once per vehicle startup and after the VehicleController reference is set. Sets state.initialized on completion; an override that fails must leave it false.

    Declaration
    protected virtual void VC_Initialize()

    VC_Initialize(VehicleController)

    Sets the VehicleController reference. Runs before VC_Initialize().

    Declaration
    public virtual void VC_Initialize(VehicleController vc)
    Parameters
    Type Name Description
    VehicleController vc

    Parent VehicleController that owns this component

    VC_LoadStateFromStateSettings()

    Reads the enabled flag and LOD index for this component type out of StateSettings. Runs during vehicle initialization.

    Declaration
    public virtual void VC_LoadStateFromStateSettings()

    VC_SetDefaults()

    Writes default values into every serialized field, and may pull default assets from Resources. Runs on vehicle reset and when the component is first added.

    Declaration
    public virtual void VC_SetDefaults()

    VC_Update(float)

    Per-frame update for input, visuals and UI. Only called while the component is active. Physics belongs in VC_FixedUpdate, not here.

    Declaration
    public virtual void VC_Update(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime

    Time elapsed since last Update in seconds

    VC_Validate(VehicleController)

    Editor-side configuration check: null references, out-of-range values, missing dependencies. Reports through Debug.LogWarning/LogError.

    Declaration
    public virtual void VC_Validate(VehicleController vc)
    Parameters
    Type Name Description
    VehicleController vc

    Parent VehicleController to validate against

    See Also

    VehicleController
    StateDefinition
    StateSettings
    ManagerVehicleComponent
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics