NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Module Manager

    ModuleManager inspector.

    ModuleManager is a ManagerVehicleComponent that manages all modules attached to a vehicle. Modules extend vehicle functionality without modifying core vehicle code.

    Overview

    Modules are VehicleComponent instances wrapped in ModuleWrapper MonoBehaviours. The wrapper pattern allows serialization and Inspector editing while maintaining the VehicleComponent lifecycle.

    Each module:

    • Can be enabled/disabled at runtime
    • Participates in the vehicle's LOD system via VehicleComponent lifecycle
    • Updates in sync with the vehicle (VC_FixedUpdate/VC_Update)
    • Has full access to VehicleController and all vehicle components

    Available Modules

    Stability & Safety

    • ABS Module - Anti-lock braking system
    • TCS Module - Traction control system
    • ESC Module - Electronic stability control

    Driving Aids

    • Cruise Control Module - Automatic speed maintenance
    • Speed Limiter Module - Maximum speed limiting
    • Arcade Module - Arcade-style handling assist

    Vehicle Types

    • Motorcycle Module - Two-wheel vehicle stabilization
    • Trailer Module - Trailer vehicle support
    • Trailer Hitch Module - Trailer attachment point

    Performance

    • NOS Module - Nitrous oxide boost
    • Fuel Module - Fuel consumption simulation
    • Aerodynamics Module - Drag and downforce

    Utility

    • Flip Over Module - Vehicle flip recovery
    • Rigging Module - Bone-based animation
    • Metrics Module - Performance data tracking
    • Air Steer Module - Airborne steering control

    Accessing Modules

    Modules are accessed via their ModuleWrapper component:

    // Access module through wrapper
    ABSModuleWrapper absWrapper = vehicleController.GetComponent<ABSModuleWrapper>();
    ABSModule absModule = absWrapper.module;
    
    // Or in one line
    var tcsModule = vehicleController.GetComponent<TCSModuleWrapper>()?.module;
    
    // Enable/disable modules
    absModule.Enable();
    tcsModule.Disable();
    
    // Check if module is active
    if (absModule != null && absModule.IsActive)
    {
        // Module is enabled and running
    }
    

    Module LOD

    Modules inherit from VehicleComponent and automatically participate in the vehicle's LOD system. Configure individual module LOD settings in StateSettings to control which modules are active at different distances from the camera.

    Creating Custom Modules

    Custom modules require both a module class (inherits VehicleComponent) and a wrapper (inherits ModuleWrapper):

    using System;
    using NWH.VehiclePhysics2;
    using NWH.VehiclePhysics2.Modules;
    
    // Module implementation
    [Serializable]
    public class CustomModule : VehicleComponent
    {
        public float customValue;
    
        public override void VC_FixedUpdate()
        {
            base.VC_FixedUpdate();
            // Module logic executed during physics step
        }
    }
    
    // Wrapper to enable component attachment and serialization
    [Serializable]
    [DisallowMultipleComponent]
    public class CustomModuleWrapper : ModuleWrapper
    {
        public CustomModule module = new();
    
        public override VehicleComponent GetModule() => module;
        public override void SetModule(VehicleComponent inModule) => module = inModule as CustomModule;
    }
    

    Add the wrapper component to a VehicleController GameObject. ModuleManager will automatically discover and manage it.

    Related

    • Vehicle Component - Base component system
    • State Settings - LOD configuration
    • Vehicle Controller - Main vehicle class
    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics