UAnimInstance::GetInstanceCurrentStateElapsedTime
#include "Animation/AnimInstance.h"
Access: public
Specifiers: UFUNCTION
Description
Returns the time in seconds that the state machine has been in its current state. Resets to zero each time the active state changes, making it useful for time-based transition conditions like "stay in this state for at least 0.5 seconds".
Caveats & Gotchas
- • The elapsed time is the time spent in the current fully-active state. During a transition crossfade it reflects the time in the destination state, not the source.
- • If the state machine weight is zero (the state machine node is not contributing to the pose), elapsed time may not increment. Always verify the state machine is active before relying on this value for gameplay logic.
Signature
UFUNCTION(BlueprintPure, Category="Animation", meta=(BlueprintInternalUseOnly = "true"))
float GetInstanceCurrentStateElapsedTime(int32 MachineIndex) const; Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| MachineIndex | int32 | Index of the state machine to query. | — |
Return Type
float Example
Prevent re-triggering a transition until a state has been active long enough C++
// Inside a custom transition rule check
bool UMyAnimInstance::CanTransitionFromIdle() const
{
int32 MachineIdx = GetStateMachineIndex(FName("LocomotionSM"));
return GetInstanceCurrentStateElapsedTime(MachineIdx) >= 0.3f;
} Tags
Version History
Introduced in: 4.8
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?