How do I freeze animation montage at end of animation cycle in code?

Hi.

I’m playing my AnimMontage like this:

void AActivateItem::PlayAnimation()
{
    // try and play a door open animation if specified
    if (OpenAnimation != NULL)
    {
        // Get the animation object for the skeletal mesh
        UAnimInstance* AnimInstance = Mesh->GetAnimInstance();
        if (AnimInstance != NULL)
        {
            if (!AnimInstance->Montage_IsActive(OpenAnimation))
            {
                AnimInstance->Montage_Play(OpenAnimation, 0.2f);
            }
        }
    }
}

When I play the animation, the anim montage plays from start to finish, and then at the end of animation cycle it goes back to the starting position. How do I stop the animation montage at end of cycle, in CODE?

I’m trying to get the door to stay open when the animation montage is finished.

I found the answer at another question. Still, I tried to google the answer for hours, and the question didn’t come up. So I’ll just answer to my own question:

When you want to FREEZE an animation montage via C++ code, set GlobalAnimRateScale to 0.0:

SkeletalMeshComponent->GlobalAnimRateScale = 0.0;

To control at which position you want to freeze the animation (I used the following code):

float f = AnimInstance->Montage_GetPosition(OpenAnimation);
if (f > 0.75)
{
    SkeletalMeshComponent->GlobalAnimRateScale = 0.0;
}

I think a cleaner method would be to set bNoSkeletonUpdate to true or bPauseAnims to true on the skeletalMeshComponent.

This works fine aswell!