Class TrailerModule
Module for vehicles that can be towed as trailers.
Inherited Members
Namespace: NWH.VehiclePhysics2.Modules.Trailer
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class TrailerModule : VehicleComponent
Remarks
Puts a trigger collider on the attachment point for TrailerHitchModule to find. While attached the trailer takes its input states from the tractor, so braking and lights follow. A vehicle that both tows and is towed (train car, road train) carries both modules.
Fields
attached
Indicates whether this trailer is attached to a towing vehicle.
Declaration
[Tooltip("True if object is trailer and is attached to a towing vehicle and also true if towing vehicle and has trailer\r\nattached.")]
public bool attached
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
Set by OnAttach and OnDetach, not by hand.
attachmentLayer
Physics layer for the attachment point trigger.
Declaration
[Tooltip("The layer of the SphereCollider used to detect if the trailer hitch module is in range.")]
public int attachmentLayer
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Must match attachmentLayer on TrailerHitchModule or the pair never detects. Use a dedicated layer to keep other colliders out of it.
attachmentPoint
Transform representing the trailer's coupling point.
Declaration
[Tooltip("If the vehicle is a trailer, this is the object placed at the point at which it will connect to the towing vehicle. If the vehicle is towing, this is the object placed at point at which trailer will be coneected.")]
public Transform attachmentPoint
Field Value
| Type | Description |
|---|---|
| Transform |
Remarks
Aligned with the hitch's attachment point on connect. Must be a child of the GameObject holding the TrailerModule. Sits at the tongue, fifth wheel pin or drawbar.
attachmentTriggerRadius
Radius of the trigger zone at the attachment point.
Declaration
[Tooltip("The radius of the SphereCollider used to detect if the trailer hitch module is in range.")]
public float attachmentTriggerRadius
Field Value
| Type | Description |
|---|---|
| float |
Remarks
Keep it smaller than the hitch's trigger radius. Typical: 0.1-0.15 precise coupler, 0.2-0.25 standard trailer coupling, 0.3-0.4 large industrial coupling.
onAttach
Event triggered when the trailer is attached to a hitch.
Declaration
[Tooltip("Called when the trailer is attached to a hitch.")]
public UnityEvent onAttach
Field Value
| Type | Description |
|---|---|
| UnityEvent |
Remarks
Fires at the end of OnAttach, after the stand is retracted and the friction cache is taken.
onDetach
Event triggered when the trailer is detached from a hitch.
Declaration
[Tooltip("Called when the trailer is detached from a hitch.")]
public UnityEvent onDetach
Field Value
| Type | Description |
|---|---|
| UnityEvent |
Remarks
Fires at the end of OnDetach, just before the trailer controller is disabled.
resetInputStatesOnDetach
Reset input states when the trailer is detached.
Declaration
[Tooltip("Should the trailer input states be reset when trailer is detached?")]
public bool resetInputStatesOnDetach
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
Clears throttle, brakes and steering on detach so the trailer does not coast on the last inputs it was handed. Leave off to keep the state.
staticHoldBypassMode
When the trailer wheels release their static-friction hold. OnRigMotion keeps the hold while the rig is stationary (so it holds on a slope under handbrake) and releases when moving or launching. OnTractorInput releases on any tractor throttle/brake/handbrake (original behaviour).
Declaration
[Tooltip("When trailer wheels drop their static hold. OnRigMotion holds while stationary (holds on slopes), releases when moving/launching. OnTractorInput = original (any tractor input releases).")]
public TrailerStaticHoldBypassMode staticHoldBypassMode
Field Value
| Type | Description |
|---|---|
| TrailerStaticHoldBypassMode |
synchronizeGearShifts
Synchronize gear shifts with the towing vehicle.
Declaration
[Tooltip("If enabled the trailer will keep in same gear as the tractor, assuming powertrain on trailer is enabled.")]
public bool synchronizeGearShifts
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
For powered trailers and articulated vehicles with a drivetrain in both sections. Needs matching forward and reverse gear counts; a mismatch drops the sync for that attachment with a warning. Does nothing unless the trailer powertrain is enabled.
trailerHitch
Reference to the hitch module this trailer is attached to.
Declaration
[NonSerialized]
public TrailerHitchModule trailerHitch
Field Value
| Type | Description |
|---|---|
| TrailerHitchModule |
Remarks
Null while detached. Route to the towing vehicle's controller through it.
trailerStand
GameObject representing the trailer's support stand or landing gear.
Declaration
[Tooltip("Object that will be disabled when trailer is attached and enabled when trailer is detached.")]
public GameObject trailerStand
Field Value
| Type | Description |
|---|---|
| GameObject |
Remarks
Deactivated on attach, reactivated on detach, so a semi-trailer does not tip forward off the hitch. Leave null for multi-axle trailers that stand on their own.
Methods
OnAttach(TrailerHitchModule)
Called when the trailer is attached to a hitch.
Declaration
public void OnAttach(TrailerHitchModule trailerHitch)
Parameters
| Type | Name | Description |
|---|---|---|
| TrailerHitchModule | trailerHitch | The hitch module attaching to this trailer |
Remarks
Turns off auto input, retracts the stand, and hooks the tractor's onEnable/onDisable so the trailer's enable state follows it. Safe to call again without an intervening OnDetach.
OnDetach()
Called when the trailer is detached from a hitch.
Declaration
public void OnDetach()
Remarks
Lowers the stand, drops the tractor listeners, restores the saved friction strengths, and disables the trailer controller last.
VC_Disable(bool)
Disables the component and stops its updates.
Declaration
public override 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 |
Overrides
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_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 override void VC_FixedUpdate(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Time elapsed since last FixedUpdate in seconds |
Overrides
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()