Montage_SetEndDelegate called prematurely when animations occur on client

Hi guys,

I shared this in the C++ subforum but also thought it may well be relevant here - so apologies if I’m wrong!

I have some fairly simple logic to run animations. I run them from C++, and when the animation ends, I like to run a simple function to set some variables.

It looks roughly like this:


    
character->GetMesh()->GetAnimInstance()->Montage_Play(animName, speed);

    FOnMontageEnded MontageBlendOutDelegate;    
    MontageBlendOutDelegate.BindUObject(this, &UCharacterAnimationManager::AnimationEnded);

    character->GetMesh()->GetAnimInstance()->Montage_SetEndDelegate(MontageBlendOutDelegate);


Although this is a minor simplification for ease of reading.

This does play the animation fine. On the server, the animation plays as expected - if I put a breakpoint in the AnimationEnded function then it occurs when expected (that is, after the animation has ended) - on the client however, the same logic doesn’t take place - the animation plays as expected, but the AnimationEnded function is immediately called at the same time as play, despite the animation clearly not being finished with.

Is this a bug, or am I missing something in the implementation?

If this code snippet is ran from an RPC, there is a chance that you are calling it twice( like starting on client, sending to server which then multicasts, so you get it back ), if so, then the same montage starts twice, which means the second montage stops the first montage. It happened to me.
If it’s not the case, i have no idea

Ah! You pointed me in the correct direction. It was indeed firing more than once, terminating the original animation. Thanks!