UAnimInstance::GetStateMachineInstance
#include "Animation/AnimInstance.h"
Access: public
Specifiers: const
Description
Retrieves the runtime state machine node instance by its index. Use this to query the current state, active transitions, state weights, and other runtime information about a state machine defined in the Animation Blueprint.
Caveats & Gotchas
- • Returns nullptr if MachineIndex is INDEX_NONE or out of range. Always validate the index (typically obtained from GetStateMachineIndex) before calling this.
- • The returned pointer is const — state machine state cannot be modified directly through this accessor. To influence state machine behavior, set anim instance variables that drive transition rules or use transition events.
Signature
const FAnimNode_StateMachine* GetStateMachineInstance(int32 MachineIndex) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| MachineIndex | int32 | The index of the state machine, obtained from GetStateMachineIndex or GetStateMachineIndexAndDescription. | — |
Return Type
const FAnimNode_StateMachine* Example
Query state machine runtime state C++
bool UMyAnimInstance::IsInLocomotionState(FName StateName) const
{
int32 MachineIndex = GetStateMachineIndex(FName("Locomotion"));
if (const FAnimNode_StateMachine* SM = GetStateMachineInstance(MachineIndex))
{
int32 StateIndex = SM->GetCurrentState();
// Compare against expected state
IAnimClassInterface* AnimClass = IAnimClassInterface::GetFromClass(GetClass());
if (const FBakedAnimationStateMachine* Desc = GetMachineDescription(AnimClass, const_cast<FAnimNode_StateMachine*>(SM)))
{
return Desc->States.IsValidIndex(StateIndex) &&
Desc->States[StateIndex].StateName == StateName;
}
}
return false;
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?