RealDocs

UKismetAnimationLibrary::K2_DistanceBetweenTwoSocketsAndMapRange

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

Description

Computes the distance between two named sockets or bones on a skeletal mesh, optionally remapping the raw distance into a normalized output range for driving things like blend weights.

Caveats & Gotchas

  • Marked NotBlueprintThreadSafe — unlike most of this library, it cannot run in the multithreaded Anim Graph evaluation and must be called from the game thread or an animation node explicitly marked to run there.
  • SocketSpaceA and SocketSpaceB are evaluated independently, so mixing e.g. World space for one and Component space for the other is valid but easy to get wrong — verify both sockets resolve in a comparable frame before comparing distances.
  • When bRemapRange is false, InRangeMin/Max and OutRangeMin/Max are ignored entirely and the raw distance is returned.

Signature

static float K2_DistanceBetweenTwoSocketsAndMapRange(const USkeletalMeshComponent* Component, const FName SocketOrBoneNameA, ERelativeTransformSpace SocketSpaceA, const FName SocketOrBoneNameB, ERelativeTransformSpace SocketSpaceB, bool bRemapRange, float InRangeMin, float InRangeMax, float OutRangeMin, float OutRangeMax)

Parameters

Name Type Description Default
Component const USkeletalMeshComponent* The skeletal component to look up the sockets/bones within.
SocketOrBoneNameA const FName Name of the first socket or bone.
SocketSpaceA ERelativeTransformSpace The transform space used to evaluate the first socket/bone.
SocketOrBoneNameB const FName Name of the second socket or bone.
SocketSpaceB ERelativeTransformSpace The transform space used to evaluate the second socket/bone.
bRemapRange bool If true, the raw distance is remapped from the input range to the output range. false
InRangeMin float Minimum of the input distance range (commonly 0.0).
InRangeMax float Maximum of the input distance range (the max expected distance).
OutRangeMin float Minimum of the output range (commonly 0.0).
OutRangeMax float Maximum of the output range (commonly 1.0).

Return Type

float

Example

Drive a blend weight from hand-to-hip distance C++
const float BlendWeight = UKismetAnimationLibrary::K2_DistanceBetweenTwoSocketsAndMapRange(
    SkeletalMeshComp, TEXT("hand_r"), ERelativeTransformSpace::RTS_World,
    TEXT("pelvis"), ERelativeTransformSpace::RTS_World,
    true, 0.0f, 100.0f, 0.0f, 1.0f);

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.