This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+3 votes

I need to change an animation's length through code. I also want the keys to be scalable. I haven't found any methods for changing an animation's length. Can I do that?

in Engine by (408 points)

3 Answers

+5 votes
Best answer
$AnimationPlayer.get_animation('YourAnimation').length = new_length
by (4,246 points)
selected by

Hahah I tried get_current_animation().get_length() but it didn't worked. However, get_animation("").length worked. Thank you

try $AnimationPlayer.current_animation_length

+1 vote

Length of your animation should be set within animation node, not the player. Try something like this.

var length = 3.0

var    your_animation =
animation_float.track_set_path(0, "Sprite:position")
your_animation.track_insert_key ( 0, 0, Vector2(0, 0))
your_animation.track_insert_key ( 0, length, Vector2(128, 0))

Basicly you create custom length variable and assign it to time argument when inserting new key to track. With continous updateMode it should work with any amout of frames, if Im not mistaken.

After animation is set, you add it to your player by add_animation() function.

Have a research here:

by (102 points)
+3 votes

You can change the speed of animation:

var speed = 0.5
$AnimationNode.playback_speed = speed

If the original Animation length is 5 seconds and you change speed to 0.5, the animation will play 10 seconds (half speed). If you change speed to 2, the animation will play at double speed and the lenght will be 2.5 seconds. 1 is for normal speed.

by (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.