NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Class Powertrain

    Coordinates the drivetrain from engine to wheels.

    Inheritance
    object
    VehicleComponent
    ManagerVehicleComponent
    Powertrain
    Inherited Members
    ManagerVehicleComponent._components
    ManagerVehicleComponent.Components
    ManagerVehicleComponent.AddAndOnboardNewComponent(VehicleComponent)
    ManagerVehicleComponent.VC_LoadStateFromStateSettings()
    ManagerVehicleComponent.VC_Update(float)
    ManagerVehicleComponent.VC_Disable(bool)
    ManagerVehicleComponent.VC_DrawGizmos()
    ManagerVehicleComponent.UpdateLOD()
    VehicleComponent.state
    VehicleComponent.vehicleController
    VehicleComponent.IsActive
    VehicleComponent.ToggleState()
    Namespace: NWH.VehiclePhysics2.Powertrain
    Assembly: NWH.VehiclePhysics2.dll
    Syntax
    [Serializable]
    public class Powertrain : ManagerVehicleComponent
    Remarks

    Components form a directed graph linked by name: engine to clutch to transmission, splitting through differentials to the wheels. Each contributes its own inertia and losses. The solver runs two passes per step: angular velocity is queried backward from the wheels to the engine, then torque is propagated forward from the engine to the wheels.

    Fields

    clutch

    Clutch component that manages power transmission between engine and transmission.

    Declaration
    public ClutchComponent clutch
    Field Value
    Type Description
    ClutchComponent

    differentials

    List of differential components that distribute torque between outputs (wheels or other differentials).

    Declaration
    public List<DifferentialComponent> differentials
    Field Value
    Type Description
    List<DifferentialComponent>
    Remarks

    2WD is a single differential feeding two wheels. AWD is three: a centre differential splitting to a front and a rear one, each of which splits left/right.

    engine

    Engine component that generates rotational power from throttle input.

    Declaration
    public EngineComponent engine
    Field Value
    Type Description
    EngineComponent

    transmission

    Transmission component that adjusts gear ratios to optimize power delivery.

    Declaration
    public TransmissionComponent transmission
    Field Value
    Type Description
    TransmissionComponent

    wheelCount

    Total number of wheels in the powertrain system.

    Declaration
    public int wheelCount
    Field Value
    Type Description
    int
    Remarks

    Cached at initialization, so it is 0 or stale in edit mode. Counts every wheel, powered or not.

    wheelGroupCount

    Total number of wheel groups (axles) in the vehicle.

    Declaration
    public int wheelGroupCount
    Field Value
    Type Description
    int

    wheelGroups

    List of wheel groups that organize wheels into logical axles for steering, braking, and other control functions.

    Declaration
    public List<WheelGroup> wheelGroups
    Field Value
    Type Description
    List<WheelGroup>
    Remarks

    A group carries the steering, brake and handbrake coefficients plus the Ackermann setting for its axle. Typical car: front (steer 1.0, brake 1.0), rear (steer 0, brake 0.7, handbrake 1.0). Multi-axle trucks add middle groups in between.

    wheels

    List of all wheel components in the powertrain, ordered front-to-back and left-to-right.

    Declaration
    public List<WheelComponent> wheels
    Field Value
    Type Description
    List<WheelComponent>
    Remarks

    Order is by Z (front first) then X (left first), so a 4-wheel car reads FL, FR, RL, RR. Differential connections and wheel group assignment both rely on that order.

    Methods

    BreakOutputCycles()

    Walks every output subgraph and clears any link that closes a loop.

    Declaration
    public void BreakOutputCycles()
    Remarks

    All four solver passes recurse into their outputs unconditionally, so a loop wired in the inspector (the output dropdown lists upstream components too) recurses until StackOverflowException, which the CLR cannot catch and which takes the process down with no log. Links are resolved by name/hash rather than by reference so this works before the components have resolved their own references.

    FillComponentList()

    Override to populate _components with your child components. Called lazily on first Components access.

    Declaration
    protected override void FillComponentList()
    Overrides
    ManagerVehicleComponent.FillComponentList()

    FillInWheels()

    Automatically finds and assigns WheelController components to the powertrain's wheel list.

    Declaration
    public void FillInWheels()
    Remarks

    Sorts the hierarchy's WheelControllers front-to-back, left-to-right and drops them into the existing wheel slots. Warns if the counts do not match.

    GetSortedWheels(VehicleController)

    Gets all WheelController components from the vehicle and sorts them in standard order.

    Declaration
    public static List<WheelController> GetSortedWheels(VehicleController vehicleController)
    Parameters
    Type Name Description
    VehicleController vehicleController

    The vehicle controller to search for wheel controllers.

    Returns
    Type Description
    List<WheelController>

    List of WheelController components sorted front-to-back (Z descending) then left-to-right (X ascending).

    Remarks

    Sorted by local Z (front first) then local X (left first), giving FL, FR, RL, RR on a 4-wheel car. Differential connections and wheel group assignment depend on that order.

    Inspector_GetPowertrainComponentFromName(string)

    Finds a powertrain component by its name string.

    Declaration
    public PowertrainComponent Inspector_GetPowertrainComponentFromName(string componentName)
    Parameters
    Type Name Description
    string componentName

    Name of the component to search for.

    Returns
    Type Description
    PowertrainComponent

    The PowertrainComponent with matching name, or null if not found.

    Remarks

    Preferred over Inspector_GetPowertrainComponentFromNameHash(int) for persisted link reconstruction since string comparison is stable across Unity versions while string.GetHashCode is not.

    Inspector_GetPowertrainComponentFromNameHash(int)

    Finds a powertrain component by its name hash code.

    Declaration
    public PowertrainComponent Inspector_GetPowertrainComponentFromNameHash(int nameHash)
    Parameters
    Type Name Description
    int nameHash

    The hash code of the component's name to search for.

    Returns
    Type Description
    PowertrainComponent

    The PowertrainComponent with matching name hash, or null if not found.

    Remarks

    Legacy lookup path for restoring serialized links at initialization.

    Inspector_GetPowertrainComponentNames()

    Gets a list of all powertrain component names for inspector dropdown menus.

    Declaration
    public List<string> Inspector_GetPowertrainComponentNames()
    Returns
    Type Description
    List<string>

    List of component names starting with "[none]" followed by engine, clutch, transmission, differentials, and wheels.

    Remarks

    Editor use only: allocates strings on every call.

    Inspector_GetPowertrainComponents()

    Gets a list of all powertrain component references for inspector operations.

    Declaration
    public List<PowertrainComponent> Inspector_GetPowertrainComponents()
    Returns
    Type Description
    List<PowertrainComponent>

    List of PowertrainComponent references with null as the first element, followed by all components.

    Remarks

    The leading null is deliberate: it lines up with the "[none]" entry from Inspector_GetPowertrainComponentNames so the two lists can be indexed together.

    Repair()

    Repairs all powertrain components by resetting their damage values to zero.

    Declaration
    public void Repair()

    VC_Enable(bool)

    Enables manager and all children (with calledByParent=true).

    Declaration
    public override bool VC_Enable(bool calledByParent)
    Parameters
    Type Name Description
    bool calledByParent
    Returns
    Type Description
    bool
    Overrides
    ManagerVehicleComponent.VC_Enable(bool)

    VC_FixedUpdate(float)

    Physics update for manager and all active children.

    Declaration
    public override void VC_FixedUpdate(float DeltaTime)
    Parameters
    Type Name Description
    float DeltaTime
    Overrides
    ManagerVehicleComponent.VC_FixedUpdate(float)

    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 override void VC_Initialize()
    Overrides
    VehicleComponent.VC_Initialize()

    VC_Initialize(VehicleController)

    Initializes manager and all children with VehicleController reference.

    Declaration
    public override void VC_Initialize(VehicleController vc)
    Parameters
    Type Name Description
    VehicleController vc
    Overrides
    ManagerVehicleComponent.VC_Initialize(VehicleController)

    VC_SetDefaults()

    Resets manager and all children to defaults.

    Declaration
    public override void VC_SetDefaults()
    Overrides
    ManagerVehicleComponent.VC_SetDefaults()

    VC_Validate(VehicleController)

    Validates manager and all enabled children. Skips if manager is disabled.

    Declaration
    public override void VC_Validate(VehicleController vc)
    Parameters
    Type Name Description
    VehicleController vc
    Overrides
    ManagerVehicleComponent.VC_Validate(VehicleController)

    See Also

    EngineComponent
    ClutchComponent
    TransmissionComponent
    DifferentialComponent
    WheelComponent
    PowertrainComponent
    VehicleController
    ManagerVehicleComponent
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics