Skip to main content

Vehicle (HVehicle)

The HVehicle class allows you to spawn a vehicle actor in the world and perform logical actions through class methods. This class also provides getter methods for obtaining data relating to specific vehicle actors. It supports input control, engine management, fuel systems, lights, sirens, and state queries.


Constructor

// Vehicles are spawned via Lua scripting on the server.

Constructor Parameters

TypeNameDefaultDescription
VectorLocation--The location to spawn the vehicle at.
RotatorRotation--The orientation of the vehicle.
stringBlueprintAsset--Long package name for the vehicle Blueprint (e.g., "/Game/Vehicles/BP_MyCar.BP_MyCar_C").
stringCollisionType"QueryAndPhysics"One of "NoCollision", "QueryOnly", "PhysicsOnly", "QueryAndPhysics".
booleanGravityEnabledtrueWhether physics gravity is enabled.

The constructor returns a table with .Object (vehicle actor) and .Movement (UModularMovementComponent).


Methods

Input Control

MethodParametersReturn TypeDescription
SetThrottleInputvalue: numbervoidSets the throttle input (typically 0.0 or 1.0).
SetSteeringInputvalue: numbervoidSets steering input (-1.0 full left to 1.0 full right).
SetBrakeInputvalue: numbervoidSets brake input (0.0 to 1.0).
SetHandBrakeInputenabled: booleanvoidEnables or disables the handbrake.
Hornstate: booleanvoidSets the horn state (true to honk).

Engine Control

MethodParametersReturn TypeDescription
HoldStarterstartTime: numbervoidHolds the engine starter for a specified duration in seconds.
ReleaseStarter--voidReleases the engine starter.
StopEngine--voidStops the engine.
SetEngineHealthhealth: numbervoidSets the engine health (0.0 destroyed to 1.0 full).
GetEngineHealth--number or nilGets the engine health (0.0 to 1.0), or nil if movement component is missing.

Fuel System

MethodParametersReturn TypeDescription
AddFuelamount: numbervoidAdds fuel to the vehicle's current fuel level (0.0 to 1.0 scale).
SetFuelamount: numbervoidSets the fuel level (0.0 to 1.0).
GetFuelRatio--numberGets the current fuel ratio (0.0 to 1.0).

State Queries

MethodParametersReturn TypeDescription
IsInReverse--booleanReturns true if the vehicle is in reverse gear.
GetRPMRatio--numberGets the normalized engine RPM (0.0 to 1.0).
GetNumberOfWheels--integerReturns the total number of wheels.
GetNumberOfWheelsTouchingGround--integerReturns how many wheels are touching the ground.
GetNumberOfDriveWheelsTouchingGround--integerReturns how many drive wheels are touching the ground.
GetMassPerWheel--numberReturns the mass per wheel.
IsBraking--booleanReturns true if the vehicle is currently braking.

Sleep and Airborne

MethodParametersReturn TypeDescription
SetCanSleepenabled: booleanvoidControls whether the vehicle can go to sleep (physics idle).
SetSleepingenabled: booleanvoidForces the vehicle into or out of sleeping state.
ApplyAirbornePhysics--voidApplies airborne physics behavior once (used when the vehicle is in the air).

Lights and Sirens

MethodParametersReturn TypeDescription
SetRightIndicatorNewState: booleanvoidSets the right indicator/blinker state.
SetLeftIndicatorNewState: booleanvoidSets the left indicator/blinker state.
SetReverseLightNewState: booleanvoidSets the reverse light state.
SetBrakeLightNewState: booleanvoidSets the brake light state.
SetHazardLightNewState: booleanvoidSets the hazard lights state.
SetRedLightIntensityValue: numbervoidSets the red light intensity (e.g., emergency light).
SetLightsEmissiveStrengthValue: numbervoidSets overall light emissive strength.
SetIndicatorLightsIntensityValue: numbervoidSets indicator light intensity.
SetIndicatorAnimationSpeedValue: numbervoidSets indicator blink animation speed.
SetSirenStatestate: booleanvoidToggles the siren state.
SetSirenEmissionStrengthAmount: numbervoidSets siren light emission strength.
SetSirenRedColorNewColor: LinearColorvoidSets the siren red color.
SetSirenBlueColorNewColor: LinearColorvoidSets the siren blue color.
SetSirenBaseColorNewColor: LinearColorvoidSets the siren base color.
SetSirenAnimationSpeedSpeed: numbervoidSets the siren animation speed.

Setup and Data Access

MethodParametersReturn TypeDescription
GetSetup--UModularVehicleData or nilReturns the vehicle's setup data.
GetWheels--tableReturns an array of UModularWheel objects.
UpdateComponentsadditionalWheels: tablevoidUpdates vehicle components with additional wheels.

AI and Navigation

MethodParametersReturn TypeDescription
RequestDirectMovemoveVelocity: Vector, forceMaxSpeed: booleanvoidRequests a direct move towards a velocity (AI/navigation helper).
RequestPathMoveinputVector: VectorvoidRequests movement through a new move input vector.
StopActiveMovement--voidStops applying further movement.
StopMovementKeepPathing--voidStops movement but continues following the current navigation path.
IsFlying--booleanWhether the vehicle is considered flying.
IsFalling--booleanWhether the vehicle is falling.
IsMovingOnGround--booleanWhether the vehicle is moving on the ground.
IsSwimming--booleanWhether the vehicle is swimming.
GetVelocityForNavMovement--VectorGets the current velocity used by nav movement.
GetMaxSpeedForNavMovement--numberGets the maximum speed used for navigation.

Replication

MethodParametersReturn TypeDescription
SetCosmeticDataOnServerdata: FRepCosmeticDatavoidSets replicated cosmetic data on the server.

Examples

Spawning and Controlling a Vehicle

// Vehicle spawning and control is handled via Lua scripting.

warning

Vehicle spawning and control should be done on the server for authoritative gameplay. Client-side vehicle control may be used for local prediction.