RealDocs

UKismetAnimationLibrary::K2_CalculateVelocityFromSockets

function AnimGraphRuntime Blueprint Since 4.0
#include "KismetAnimationLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintCallable

Description

Tracks the motion of an offset position on a bone/socket over time — optionally relative to another bone/socket as a moving reference frame — and returns a smoothed, optionally eased velocity magnitude. Used for things like measuring a hand's velocity relative to the pelvis.

Caveats & Gotchas

  • Marked NotBlueprintThreadSafe — cannot run inside multithreaded Anim Graph evaluation, unlike most of this library.
  • History must be a persistent variable across calls, exactly like K2_CalculateVelocityFromPositionHistory — passing a fresh FPositionHistory each call breaks the velocity computation.
  • ReferenceSocketOrBone lets the tracked position move with a parent bone (e.g. tracking a hand relative to the pelvis instead of the world) — set it to None to track in the given SocketSpace directly instead.
  • CustomCurve is only read when EasingType is set to the Custom easing type; otherwise it's ignored.

Signature

static float K2_CalculateVelocityFromSockets(float DeltaSeconds, USkeletalMeshComponent * Component, const FName SocketOrBoneName, const FName ReferenceSocketOrBone, ERelativeTransformSpace SocketSpace, FVector OffsetInBoneSpace, UPARAM(ref) FPositionHistory& History, int32 NumberOfSamples, float VelocityMin, float VelocityMax, EEasingFuncType EasingType, const FRuntimeFloatCurve& CustomCurve)

Parameters

Name Type Description Default
DeltaSeconds float Time passed in seconds since the last call.
Component USkeletalMeshComponent* The skeletal component to look up the bone/socket within.
SocketOrBoneName const FName Name of the bone/socket to track over time.
ReferenceSocketOrBone const FName Bone/socket to use as a frame of reference, or None for world space.
SocketSpace ERelativeTransformSpace The transform space used to evaluate the tracked socket/bone.
OffsetInBoneSpace FVector Relative position offset, in the space of the tracked bone/socket, to track over time.
History FPositionHistory& Persistent storage for the position history; must be a variable that stays alive between calls.
NumberOfSamples int32 Number of samples to retain for the history — higher values smooth the velocity result more. 16
VelocityMin float Minimum velocity for normalization; if both min and max are 0, normalization is disabled. 0.f
VelocityMax float Maximum velocity for normalization; if both min and max are 0, normalization is disabled. 128.f
EasingType EEasingFuncType Easing function applied when normalizing the velocity result.
CustomCurve const FRuntimeFloatCurve& Curve asset used when EasingType is set to Custom.

Return Type

float

Example

Track hand velocity relative to the pelvis C++
// FPositionHistory HandVelocityHistory; // member variable, persists across ticks
const float HandSpeed = UKismetAnimationLibrary::K2_CalculateVelocityFromSockets(
    DeltaSeconds, SkeletalMeshComp, TEXT("hand_r"), TEXT("pelvis"),
    ERelativeTransformSpace::RTS_World, FVector::ZeroVector,
    HandVelocityHistory, 16, 0.0f, 128.0f, EEasingFuncType::Linear, FRuntimeFloatCurve());

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.