How to change AnimatedSprite2D animation keeping playback speed

Godot Version

4.2.1

Question

When changing the animation of an AnimatedSprite2D with set_animation(animation_name), the playback speed drops to about 1/2. If I change it back to the original animation, it plays back at normal speed. I’ve tried explicitly setting set_frame_and_progress(0,0) but it doesn’t solve the problem. I’ve checked the SpritFrames speed_scale value which is 1.0 on both animations. They also have the same amount of frames (12).

What is the proper way of changing the animation keeping the playback speed?

I think you made a mistake on creating the animations in animated sprite, check properly the speed of animation (FPS) of all animations

Thanks. That seems to be where the problem is. But why does the FPS change when changing the animation? When I create the node, I explicitly set the animation speed with:

animationNode.get_sprite_frames().set_animation_speed(anim, 12)

It works as expected and, when checked with the debugger, it is correctly set to 12 FPS.

But when I change the animation and monitor with the debugger, it’s set to 5 FPS. Where or why does it change? I can manually set it to 12 FPS, but I’d like to keep the original speed without having to do it manually, so different nodes could run at differents speeds.

1 Like