RealDocs

UAnimInstance::GetRelevantAnimTime

function Engine Blueprint Since 4.8
#include "Animation/AnimInstance.h"
Access: public Specifiers: UFUNCTION

Description

Returns the current playback position in seconds of the most relevant animation sequence in the specified state. Use this to trigger gameplay events (footsteps, hit windows, VFX) at specific animation positions.

Caveats & Gotchas

  • The time value advances at the animation's current play rate. If the animation is being played at a custom rate, the time does not correspond to wall-clock time. Use GetRelevantAnimTimeFraction for a rate-independent measure.
  • On the same frame that a transition fires, the state's relevant anim time may reset to its start position. Check GetInstanceStateWeight > 0 first if you need to avoid false triggers at transition boundaries.

Signature

UFUNCTION(BlueprintPure, Category="Animation", meta=(BlueprintInternalUseOnly = "true"))
float GetRelevantAnimTime(int32 MachineIndex, int32 StateIndex) const;

Parameters

Name Type Description Default
MachineIndex int32 Index of the state machine containing the state.
StateIndex int32 Index of the state to query.

Return Type

float

Example

Spawn a footstep sound at a specific frame position C++
// Called from NativeUpdateAnimation each tick
void UMyAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
	Super::NativeUpdateAnimation(DeltaSeconds);

	float AnimTime = GetRelevantAnimTime(LocomotionMachineIdx, WalkStateIdx);
	// Foot strike at 0.25s and 0.75s in the walk cycle
	if (FMath::IsNearlyEqual(AnimTime, 0.25f, DeltaSeconds * 0.5f))
	{
		PlayFootstepSound(EFoot::Left);
	}
}

Version History

Introduced in: 4.8

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.