Description
Returns a normalised copy of the vector, or ResultIfZero if the vector is too short to safely normalise. Does not modify the original vector.
Signature
TVector<T> GetSafeNormal(T Tolerance = UE_SMALL_NUMBER, const TVector<T>& ResultIfZero = ZeroVector) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Tolerance | float | Minimum squared length required to normalise. Below this, ResultIfZero is returned. | UE_SMALL_NUMBER |
| ResultIfZero | const FVector& | Vector returned when the length is below Tolerance. Defaults to FVector::ZeroVector. | FVector::ZeroVector |
Return Type
FVector Caveats & Gotchas
- • Unlike Normalize() which modifies in place, GetSafeNormal() returns a new vector and leaves the original unchanged.
- • The Tolerance check is against squared length, not length — UE_SMALL_NUMBER (1e-8) means vectors shorter than ~0.0001 units are treated as zero.
- • GetUnsafeNormal() is faster but will produce NaN/Inf for zero-length vectors — only use it when you can guarantee the vector is non-zero.
Example
Get direction to target safely C++
// Safe: returns ZeroVector if actor is at same location
FVector Direction = (TargetLocation - GetActorLocation()).GetSafeNormal();
if (!Direction.IsNearlyZero())
{
// Use direction to orient or apply force
Projectile->SetActorRotation(Direction.Rotation());
} See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?