AnimationPlayer: can I change "Speed scale" on runtime?

Godot Version

4.2.1

Question

I have an animation for a rolling ball, and I want it to be played faster, slower, or don’t play at all depending on the character speed.

I was using an AnimatedSprite first, and I was able to change the speed scale, but now I’ve switched to AnimationPlayer and changing the value, either from script or in the editor, seems to do nothing (it does change the speed in the editor while not running the project, but not in the game). Am I missing something, or this just can’t be done?

I just tested it and it works fine:

extends Node


@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var label: Label = $Label


func _process(delta: float) -> void:
	if Input.is_action_just_pressed("ui_left"):
		animation_player.speed_scale -= 0.5
	if Input.is_action_just_pressed("ui_right"):
		animation_player.speed_scale += 0.5

	label.text = "Animation speed: %.2f" % animation_player.get_playing_speed()
2 Likes

D’oh! Will try again later, and get back with a reproduction if it still fails.

Yep, definitely not working on my end. Here’s a simple project to reproduce it:

To reproduce the issue:

1- Open the project and run it. You’ll see a ball rolling

2- Use arrow up/down to increase/decrease the animation player speed scale. You’ll see the value changes in the console and in the Remote tab, but the animation speed in the game window doesn’t change.

I’m sure I’m missing some noob stuff here, but don’t know what. Any help is greatly appreciated :slight_smile:

You are using an AnimationTree which will override and control the Animations itself. The AnimationPlayer properties won’t be used.

If you want to change the speed of an Animation in an AnimationTree you’ll need to use an AnimationNodeBlendTree with an AnimationNodeTimeScale node

I fixed it here Data package from February 19th. - FileTransfer.io

1 Like

Nice! Thank you very much :slight_smile:

What is “Animation”?
What is “AnimationPlayer”?
What is “AnimationTree”? Why override “Animation”?
“In an AnimationTree you need to use AnimationNodeBlendTree with AnimationNodeTimeScale nodes”,
But you just use “animation_player.speed_scale -= 0.5” and “$AnimationPlayer” and “% animation_player.get_playing_speed()”,
I didn’t understand the document “AnimationNodeBlendTree”.
Return the position or node name of the “sub-animation”, disconnect and delete the sub-animation.
What is a sub-animation?
“node_changed” is emitted when the input port information changes.
What is “Input Port Information”?
There are many texts that are difficult for me to understand.
I barely understood it from the official documentation.
Where did you find out that you need to use “AnimationNodeBlendTree”?
Only the first line of text has “AnimationTree”:
“A subtree of various types of AnimationNode used for complex animations. By AnimationTree.”