RealDocs

UKismetMathLibrary::GetDirectionUnitVector

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Returns the unit direction vector pointing from one world position to another. Returns (0,0,0) if the two positions are identical.

Caveats & Gotchas

  • Returns a zero vector when From and To are equal rather than asserting or returning an undefined direction — always check for the zero-vector case if the positions might coincide (e.g., projectile spawned exactly on target).
  • Internally computes (To - From) and normalizes; the function performs a square-root. For performance-critical code that only needs the squared distance too, compute the delta manually to avoid doing both separately.

Signature

static UE_INL_API FVector GetDirectionUnitVector(FVector From, FVector To);

Parameters

Name Type Description Default
From FVector The starting position.
To FVector The target position.

Return Type

FVector

Example

Aim a projectile toward a target C++
FVector LaunchDir = UKismetMathLibrary::GetDirectionUnitVector(
    GetActorLocation(),
    TargetActor->GetActorLocation());
if (!LaunchDir.IsZero())
{
    ProjectileMovement->Velocity = LaunchDir * LaunchSpeed;
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.