ACharacter::PlayAnimMontage
#include "GameFramework/Character.h"
Access: public
Specifiers: virtualBlueprintCallableENGINE_API
Description
Plays an animation montage on the character's mesh. Returns the length of the montage in seconds, or 0.f if the montage failed to play.
Caveats & Gotchas
- • Returns 0.f (not a negative sentinel) on failure, including when AnimMontage is null or the mesh has no valid AnimInstance. Always check the return value before scheduling logic based on montage length.
- • This does not handle replication automatically. On a server, the montage plays locally; clients will only see it if you also replicate the trigger (e.g. via a multicast RPC or a replicated montage property).
- • If the same montage is already playing, calling PlayAnimMontage again will restart it from the beginning (or the specified section), which may cause a visible pop if not intended.
Signature
ENGINE_API virtual float PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate = 1.f, FName StartSectionName = NAME_None); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| AnimMontage | class UAnimMontage* | The montage asset to play. | — |
| InPlayRate | float | Playback rate multiplier. 1.0 is normal speed; values above 1.0 speed up, below 1.0 slow down. | 1.f |
| StartSectionName | FName | Optional name of the montage section to start from. Defaults to the first section. | NAME_None |
Return Type
float Examples
Play an attack montage on BeginPlay via Play Anim Montage
Blueprint
Play a hit reaction montage C++
void AMyCharacter::PlayHitReaction()
{
if (HitReactionMontage)
{
const float Duration = PlayAnimMontage(HitReactionMontage);
if (Duration <= 0.f)
{
UE_LOG(LogTemp, Warning, TEXT("Failed to play hit reaction montage"));
}
}
} Start a montage from a specific section at half speed C++
PlayAnimMontage(AttackMontage, 0.5f, FName("HeavySwing")); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?