RealDocs

UKismetMathLibrary::Matrix_GetUnitAxis

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

Description

Returns the requested row vector of the matrix, normalised to unit length. Use this when you only need the direction the axis points, independent of any scale embedded in the matrix.

Caveats & Gotchas

  • If the row vector has zero length (degenerate/zero-scaled axis), the normalisation will produce a zero vector rather than a valid direction. Check for this case if the input may come from user-controlled data.
  • Unlike AActor::GetActorForwardVector which reads from the component transform, this operates directly on a raw FMatrix — make sure the matrix is in the expected coordinate space (e.g., world space vs local space) before interpreting the result.

Signature

static UE_INL_API FVector Matrix_GetUnitAxis(const FMatrix& M, TEnumAsByte<EAxis::Type> Axis)

Parameters

Name Type Description Default
M const FMatrix& The matrix to read the axis from.
Axis TEnumAsByte<EAxis::Type> Which axis to return: EAxis::X, EAxis::Y, or EAxis::Z.

Return Type

FVector

Example

Get the world-space forward direction of an actor C++
FMatrix M = MyActor->GetTransform().ToMatrixWithScale();
FVector Forward = UKismetMathLibrary::Matrix_GetUnitAxis(M, EAxis::X);
// Forward is a unit vector pointing along the actor's X axis in world space

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.