UAnimInstance::AddNativeStateEntryBinding
#include "Animation/AnimInstance.h"
Access: public
Specifiers: ENGINE_API
Description
Binds a native C++ delegate that fires when the specified state in an animation state machine is entered. Use this to trigger game logic (sound, VFX, state changes) directly from C++ in response to state machine transitions.
Caveats & Gotchas
- • The delegate fires once per entry — if the state machine re-enters the same state (e.g., after a self-transition), the delegate fires again.
- • State and machine names must match the Animation Blueprint graph exactly (case-sensitive). Mismatched names silently fail. Register bindings in NativeInitializeAnimation.
Signature
ENGINE_API void AddNativeStateEntryBinding(const FName& MachineName, const FName& StateName, const FOnGraphStateChanged& NativeEnteredDelegate, const FName& BindingName = NAME_None) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| MachineName | const FName& | Name of the state machine containing the state. | — |
| StateName | const FName& | Name of the state to bind entry notification to. | — |
| NativeEnteredDelegate | const FOnGraphStateChanged& | Delegate to call when the state machine enters this state. | — |
| BindingName | const FName& | Optional name to identify this binding for later queries. | NAME_None |
Return Type
void Example
Play a sound when entering the attack state C++
void UMyAnimInstance::NativeInitializeAnimation()
{
Super::NativeInitializeAnimation();
FOnGraphStateChanged EntryDelegate;
EntryDelegate.BindUObject(this, &UMyAnimInstance::OnEnterAttackState);
AddNativeStateEntryBinding(FName("Locomotion"), FName("Attack"), EntryDelegate);
}
void UMyAnimInstance::OnEnterAttackState(const FAnimNode_StateMachine& Machine, int32 PrevStateIndex, int32 NextStateIndex)
{
UGameplayStatics::PlaySoundAtLocation(this, AttackSound, GetSkelMeshComponent()->GetComponentLocation());
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?