UKismetMathLibrary::TimespanRatio
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Computes the ratio A / B as a float, returning 0.0 when B is zero. Useful for progress bars and normalisation where you need a 0-1 scalar from two timespans.
Caveats & Gotchas
- • The return type is float (32-bit), not double, so sub-microsecond precision is lost. For very long timespans the ratio may have only 6–7 significant digits. This is fine for UI but not for high-precision scheduling.
- • When B is zero the function returns 0.0 rather than infinity or NaN, which is safe for UI but may silently mask a programming error. If you expect B to always be non-zero, add an assertion before calling.
Signature
static UE_INL_API float TimespanRatio( FTimespan A, FTimespan B ); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FTimespan | Numerator timespan. | — |
| B | FTimespan | Denominator timespan. If zero, returns 0.0 to avoid division by zero. | — |
Return Type
float Example
Drive a progress bar from elapsed vs. total time C++
FTimespan Elapsed = FDateTime::UtcNow() - RoundStartTime;
FTimespan Total = UKismetMathLibrary::FromMinutes(10.0);
float Progress = UKismetMathLibrary::TimespanRatio(Elapsed, Total);
ProgressBar->SetPercent(FMath::Clamp(Progress, 0.f, 1.f)); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?