As a Roblox developer, it is currently too hard to play an animation without a visible 1-frame delay.
To better explain my feature request, consider this documentation page showing when certain jobs happen during a frame. The image on that web-page is very important.
From my understanding after a whole day of debugging, it seems that animations always get updated during the Simulation Job -> Internal Legacy Step -> Animators
step. This means that - as far as I can tell - an animation that is played using AnimationTrack:Play()
will not start playing until this step is reached.
Depending on when in a frame you call AnimationTrack:Play()
, it means that sometimes the Rendering -> Screen Drawing
step is executed before the animation actually starts playing. This causes an extra frame to be rendered to the screen where the animation is not visible.
So why is this important?
Animations are usually tied to user input. When you press space-bar to jump, you play an animation of your character jumping! If you click to swing your sword, you play the animation of you swinging your sword!
Unfortunately, the User Input
job is handled right before the Rendering
job starts. So if you execute an AnimationTrack:Play()
call during a user-input event (like pressing a GUI button or pressing a key on your keyboard), your animations will visibly be delayed by one frame. In certain situations this causes visual stutters. Below is a video of a main menu I am working on where if you click on a character, it will show the character’s model and play an animation. In this case you can see that for one frame the characters are in a T-pose.
You may have to play the video at a slower speed to observe the issue.
The problem in this case is that I parent a model to the Workspace and play an animation as soon as I click a GUI button. The parenting is executed right away (before the rendering step is executed) but the animation will not get played until during the animation job. This causes the characters to T-pose for the first frame.
To work around this problem I currently have to add the following line of code to delay playing the animation until later in the frame:
game:GetService("RunService").PreAnimation:Wait()
This solution is not perfect because it still causes animations to be played a frame late. It only solves the stutter from the video above.
If Roblox is able to address this issue, it would improve my development experience because Roblox developers shouldn’t have to worry about when in a frame they play an animation. When you play an animation it should be immediately visible on screen. Writing code that delays the execution of an animation until later in a frame to prevent stutters is not intuitive and not something you can expect an average developer to know about.