0 votes

The title says it all

I have an AnimationPlayer node with 8 frames and I only want to play from 0 to 0.4
(4 frames)


I was hoping there might be a solution like $Ani.play("Run",start=0,end=0.4)

is there any way to achieve the desired result?

Godot version v3.4.stable.mono
in Engine by (46 points)

start :
$Ani.seek("strart:float", true)

look AnimationPlayer "Doc" = document

but I don't know the ending

2 Answers

0 votes

Not certain that this is the optimal method but it could certainly be done this way:

Add an AnimationTree, add a NodeBlendTree and select your animation player. Add the node structure as:

Animation --> TimeScale --> Seek --> Output

In the AnimationTree script make method along these lines:

var playing_segment = -1

func play_segment(start):
    if playing_segment == -1:
        set("parameters/Seek/seek_position", start)
        set("parameters/TimeScale/scale", 1)
        playing_segment = start

Then to stop the animation add a Call Method Track in your animation player calling a stop_segment() method in your animation tree. You can use the playing_segment value to add some logic here and make sure the right animation stops in the right place depending on which segment is playing. Remember to reset it to -1 when you're done.

Here are the docs for animation_tree if you're not familiar with it:


by (1,785 points)

This is really unnecessary. A Call Method track by itself would suffice.

My suggestion did use a Call Method Track in exactly the way you suggested.

I also added the AnimationTree to have the additional functionality of being able to start as well as stop the animation at any point, something I thought the OP might find useful.

AnimationPlayer already has methods advance() and seek() and a property current_animation_position. You could acheive the same thing without the added complexity.

Making a basic animation tree is not complex, it literally takes a few seconds and allows for easy and convenient control which is infinitely more scalable and manageable than relying on an animation player alone.

Regardless, I prefaced my suggestion with Not certain that this is the optimal method but it could certainly be done this way:

If you believe you have a better approach then perhaps next time just leave your own suggestion on a separate thread and let the OP decide which approach they prefer rather than sharing your opinion on a perfectly valid approach from another user. And maybe also check that what you are suggesting hasn't already been covered.

Let's leave this here.

0 votes

The easiest way would be to add a Call Method track to the animation which can simply call the stop() method. Add the keyframe at the time you want the animation to stop at.

If you need to sometimes play the whole animation, make a custom method to hold the logic and use the Call Method track to call your custom method instead.

by (100 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 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 webmaster@godotengine.org with your username.