I want to have a “Play Slot Animation as Dynamic Montage” node where I can dynamically edit the “Enable Auto Blend Out” option that montage assets have.
So I created a C++ Blueprint Function Library and created a function called:
Cpp_BPFL_Animate_PlaySlotAnimation
Here is the function:
UAnimMontage* UCpp_BPFL_Animate::Cpp_BPFL_Animate_PlaySlotAnimation(
UAnimInstance* AnimInstance,
UAnimSequenceBase* Asset,
FName SlotNodeName,
bool bEnableAutoBlendOut,
float BlendInTime,
float BlendOutTime,
float InPlayRate
)
{
UAnimMontage* CreatedMontage = nullptr;
if (!AnimInstance || !Asset) {
UE_LOG(LogTemp, Warning, TEXT("AnimInstance or Asset is null"));
return nullptr;
}
if (AnimInstance && Asset)
{
// Play the animation and get the created UAnimMontage instance
CreatedMontage = AnimInstance->PlaySlotAnimationAsDynamicMontage(
Asset,
SlotNodeName,
BlendInTime,
BlendOutTime,
InPlayRate
);
if (CreatedMontage)
{
// Modify the montage EnableAutoBlendOut property
CreatedMontage->bEnableAutoBlendOut = bEnableAutoBlendOut;
// Modify other properties if needed
CreatedMontage->BlendIn.SetBlendTime(BlendInTime);
CreatedMontage->BlendOut.SetBlendTime(BlendOutTime);
CreatedMontage->RateScale = InPlayRate;
}
else {
UE_LOG(LogTemp, Warning, TEXT("Failed to create Montage"));
}
}
return CreatedMontage;
}
Everything is working as intended except for:
CreatedMontage->bEnableAutoBlendOut = bEnableAutoBlendOut;
I can play the Animation Sequence that I need to play, and set its Blend In/Out or Play Rate but the Enable Auto Blend Out setting is not getting activated.
I need to play a montage from any given Animation Sequence and I want that montage not to go back to its original pose after it ends.
TLDR:
How to make CreatedMontage->bEnableAutoBlendOut
work in C++?