NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class VehicleComponent

    Abstract base class for all vehicle subsystems and modules in NWH Vehicle Physics 2. Provides a standardized interface for initialization, updating, state management, and LOD handling.

    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

    VehicleComponent is the foundation of the modular architecture. All major vehicle systems (Powertrain, Steering, Brakes, Effects, Sound, etc.) inherit from this class. Components can be enabled/disabled at runtime and support LOD optimization through StateSettings. The VC_ prefix is used for all virtual methods to avoid confusion with Unity callbacks.

    Fields

    state

    Runtime state information for this component including enabled status and LOD settings. Managed automatically by the state system.

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

    vehicleController

    Reference to the parent VehicleController that owns this component. Set during initialization via VC_Initialize(VehicleController).

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

    Properties

    IsActive

    Indicates if the component is both initialized and enabled. Components are only updated when active.

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

    Returns true only when the component has been successfully initialized and is currently enabled. Use this to check if a component is operational.

    Methods

    ToggleState()

    Toggles the component between enabled and disabled states. Useful for runtime state changes from UI or scripts.

    Declaration
    public virtual void ToggleState()
    Remarks

    Only works during play mode. Manually toggles state regardless of LOD settings. Note that LOD system may override manual state changes if lodIndex >= 0.

    UpdateLOD()

    Updates the component's enabled state based on current LOD level. Automatically enables/disables the component as the vehicle moves closer/farther from camera.

    Declaration
    public virtual void UpdateLOD()
    Remarks

    Called by the LOD system when camera distance changes. Components with lodIndex >= 0 are controlled by LOD. Components with lodIndex = -1 ignore LOD and maintain manual control.

    VC_Disable(bool)

    Disables the component and stops updates. Override to add component-specific disable logic.

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

    True if called by parent component or LOD system

    Returns
    Type Description
    bool

    True if successfully disabled, false otherwise

    Remarks

    Component must be initialized before it can be disabled. Tracks whether disable was called by parent to manage LOD system interaction.

    VC_DrawGizmos()

    Draws debug gizmos in the Scene view when the vehicle is selected. Override to visualize component-specific debug information.

    Declaration
    public virtual void VC_DrawGizmos()
    Remarks

    Only called in Editor when the component is enabled. Use Gizmos and Handles API to draw debug visualizations.

    VC_Enable(bool)

    Enables the component and starts updates. Override to add component-specific enable logic.

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

    True if called by parent component or LOD system

    Returns
    Type Description
    bool

    True if successfully enabled, false otherwise

    Remarks

    Will initialize the component if not already initialized. Components disabled by LOD system will track the parent caller to prevent manual enabling while LOD is controlling state.

    VC_FixedUpdate(float)

    Physics update called at fixed intervals. Override to implement physics-based behavior.

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

    Time elapsed since last FixedUpdate in seconds

    Remarks

    Only called when the component is active (initialized and enabled). Use for physics calculations, force application, and other fixed-timestep operations. Called from VehicleController.FixedUpdate().

    VC_Initialize()

    Initializes the component's internal systems and resources. Called once during vehicle startup after the VehicleController reference is set.

    Declaration
    protected virtual void VC_Initialize()
    Remarks

    Override this to set up component-specific resources, cache references, or perform one-time initialization. Sets state.initialized to true on completion.

    VC_Initialize(VehicleController)

    Sets the VehicleController reference for this component. Called during vehicle initialization 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()

    Loads the component's enabled/disabled and LOD configuration from StateSettings. Called during vehicle initialization.

    Declaration
    public virtual void VC_LoadStateFromStateSettings()
    Remarks

    Reads the StateSettings ScriptableObject to determine if this component should be enabled and at which LOD levels it should be active.

    VC_SetDefaults()

    Resets the component to default configuration. Override to provide component-specific default values.

    Declaration
    public virtual void VC_SetDefaults()
    Remarks

    Called when the vehicle is reset or when first added to a GameObject. Should set all serialized fields to sensible default values. May load default assets from Resources folder.

    VC_Update(float)

    Frame-rate dependent update called every frame. Override for visual updates and input handling.

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

    Time elapsed since last Update in seconds

    Remarks

    Only called when the component is active (initialized and enabled). Use for visual effects, UI updates, and other frame-dependent operations. Avoid physics calculations here - use VC_FixedUpdate instead.

    VC_Validate(VehicleController)

    Validates the component configuration and reports any setup issues. Override to implement component-specific validation rules.

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

    Parent VehicleController to validate against

    Remarks

    Called in Editor when validation is triggered manually or automatically. Should use Debug.LogWarning/Error to report configuration problems. Check for null references, invalid values, missing dependencies, etc.

    See Also

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