UKismetMathLibrary::Matrix_ToQuat
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Converts the rotation part of the matrix to a quaternion. Prefer this over Matrix_GetRotator when the result will be used for interpolation or blending, as quaternions avoid gimbal lock.
Caveats & Gotchas
- • The header explicitly warns: the rotation rows must be unit length for the result to be correct. Always call Matrix_GetMatrixWithoutScale first if the matrix may contain scale — passing a scaled matrix produces an unnormalised quaternion.
- • The function uses Shepperd's method internally and selects among four numerically stable code paths based on the trace; nevertheless, numerical drift can accumulate over many concatenated rotations. Normalise the resulting FQuat with FQuat::Normalize() if it will be used over many frames.
Signature
static UE_INL_API FQuat Matrix_ToQuat(const FMatrix& M) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| M | const FMatrix& | The matrix to convert. The rotation part must have unit-length row vectors. | — |
Return Type
FQuat Example
Convert a transform matrix to a quaternion for SLERP interpolation C++
FMatrix M = TargetActor->GetTransform().ToMatrixNoScale();
FQuat TargetQuat = UKismetMathLibrary::Matrix_ToQuat(M);
FQuat CurrentQuat = GetActorQuat();
FQuat Interpolated = FQuat::Slerp(CurrentQuat, TargetQuat, DeltaTime * TurnSpeed);
SetActorRotation(Interpolated); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?