In my game i have a menu where there is a slider and you can click on 4 different buttons to move a slider to that position. I have a UMG animation with 4 keyframes with each keyframe at a differnet posisiton to move the slider to. In my blueprint i want to just play the animation and just stop the animation at the specific keyframe / time.
My first solution was to have a timer that would pause the animation after the specific time causing the slider to move to the correct position and then stop. The issue with this solution was that the timer didn’t always match up with the time of the animation so sometimes the animation would stop a little before or after the desired position.
The next solution is to have an animation for each position and just call the animation that i want to move the slider to but this is too much work
The final solution i’ve come up with that seems to work is to modify the UUMGSequencePlayer::Tick and Play() to take in a EndOnTime parameter that checks the current animation time and if its over the end time set the last position and current position to the end time and stop the animation. This works with 1 of my animations that the keyframes are 1 second apart stopping at the correct position. It also works with keyframes that are at 0.01 secs apart for snapping to make the slider just appear at the correct position when re-opening the menu
This is the code that i added to the Tick function
.
if (EndCursorPosition != 0 && TimeCursorPosition >= EndCursorPosition || Snap)
{
TimeCursorPosition = LastTimePosition = EndCursorPosition;
PlayerStatus = EMovieScenePlayerStatus::Stopped;
OnSequenceFinishedPlayingEvent.Broadcast(*this);
Animation->OnAnimationFinished.Broadcast();
}
I hope this helps anyone that wants to snap / stop UMG animations at specific times.