UKismetMathLibrary::Subtract_VectorVector
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Subtracts vector B from vector A component-wise. The canonical way to compute a direction vector or positional delta between two points.
Caveats & Gotchas
- • Order matters: A - B gives the vector pointing from B toward A. Swapping the inputs reverses the direction — a common source of subtle orientation bugs.
- • The result is not normalized; call GetSafeNormal() on the result if you need a unit direction vector for things like line traces or movement inputs.
Signature
static UE_INL_API FVector Subtract_VectorVector(FVector A, FVector B); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FVector | The vector to subtract from. | — |
| B | FVector | The vector to subtract. | — |
Return Type
FVector Example
Compute direction from enemy to player C++
FVector PlayerPos = Player->GetActorLocation();
FVector EnemyPos = Enemy->GetActorLocation();
FVector ToPlayer = UKismetMathLibrary::Subtract_VectorVector(PlayerPos, EnemyPos);
FVector Direction = ToPlayer.GetSafeNormal(); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?