Description
The primary math utility struct in Unreal Engine, providing static functions for arithmetic, interpolation, trigonometry, random number generation, and geometric operations. Inherits platform-specific implementations from FPlatformMath via FGenericPlatformMath.
Caveats & Gotchas
- • Many functions have both float and double overloads. When mixing float/double arguments, UE will promote to the higher-precision type via MIX_FLOATS macros — but implicit promotion can silently increase cost in hot paths.
- • Trigonometric functions (Sin, Cos, Atan2) take angles in radians. FRotator stores degrees. Use FMath::DegreesToRadians / FMath::RadiansToDegrees to convert.
- • FMath::RandRange seeded by FMath::RandInit — the global seed is shared across the process. For deterministic random sequences, use FRandomStream instead.
Example
Common usage in a tick function C++
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Smoothly interpolate a float toward a target
CurrentSpeed = FMath::FInterpTo(CurrentSpeed, TargetSpeed, DeltaTime, 5.0f);
// Clamp health to valid range
Health = FMath::Clamp(Health, 0.0f, MaxHealth);
// Random chance per tick (roughly once per second at 60fps)
if (FMath::RandRange(0, 59) == 0)
{
TriggerRandomEvent();
}
} Functions (14)
Math 14 ▼
| Access | Type | Name |
|---|---|---|
| public | function | FMath::Abs |
| public | function | FMath::Cos |
| public | function | FMath::Sin |
| public | function | FMath::Atan2 |
| public | function | FMath::Clamp |
| public | function | FMath::FInterpTo |
| public | function | FMath::GetMappedRangeValueClamped |
| public | function | FMath::IsNearlyEqual |
| public | function | FMath::IsNearlyZero |
| public | function | FMath::Lerp |
| public | function | FMath::RandRange |
| public | function | FMath::Sqrt |
| public | function | FMath::Square |
| public | function | FMath::VInterpTo |
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?