Pausing and resuming animation - animation player's current animation is empty (but playing?)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nephtis

Godot 3.2.

Update

Doing print(anim_player.get_current_animation()) prints nothing, so I’m led to believe that the current animation is somehow ending up being null - but strangely, the correct animation plays in-game when I trigger it, and there are no console errors.

I think the issue may be to do with the fact that I’m triggering the animation through an AnimationNodeStateMachinePlayback, so even though it refers to an AnimationPlayer’s animation, the AnimationPlayer isn’t actually “playing” it itself, so its current animation ends up being null.

Original Question

I am trying to set up an animation that I need to pause until some input is received, at which point it resumes. (Specifically I want to charge up for a big jump, which involves crouching, holding the crouch position to charge up, and then jumping).

I know I could do this by having separate animations for each part of the overall animation, but to me, this seems silly when it should be possible to have one animation and step through it.

What I’ve tried so far doesn’t give me the desired effect, or does nothing at all.

In the following examples, I’m pretty sure they’re both pointing to the correct nodes, and nothing else is interfering with these attributes.

AnimationPlayer:

anim_player.stop(false) # this is supposedly how to do it according to the docs, but for me it does nothing

anim_player.seek() # gives me an error: E 0:00:01.403 seek: Condition "!playback.current.from" is true. <C++ Source> scene/animation/animation_player.cpp:1330 @ seek()

anim_player.playback_active = false # does nothing

AnimationTree:

anim_tree.active = false # pauses the animation, but upon setting it back to = true, it starts from the beginning

anim_tree.stop() and anim_tree.start() # also plays from the beginning

anim_tree.process_mode = AnimationTree.ANIMATION_PROCESS_MANUAL # also pauses the animation, but then changing it back to PROCESS_PHYSICS restarts it

I then read about AnimationNodeTimeScale, and I thought that if I set the speed to 0.0 it would pause the animation, but it doesn’t seem to do anything, although I couldn’t find any examples of how to get access to this node so maybe I referenced it incorrectly.

Hi,
have you tried to stop the AnimationTree with

atree.process_mode = AnimationTree.ANIMATION_PROCESS_MANUAL

wich will only advance when advance is called.

klaas | 2020-09-29 10:52

Hi klaas, I did also try that but found that it reset the animation to the beginning. I did it via set_process_mode() so maybe I’ll try accessing it directly.

Nephtis | 2020-09-29 11:13

have a look here … this seems to solve the issue

Reddit - Dive into anything

klaas | 2020-09-29 11:16

Setting process_mode gave the same result as the other animation tree attempts = the animation paused, but then reset to the beginning when I set process_mode back.

That link uses seek() which has been giving me a console error; although I do notice that if I do anim_player.get_current_animation() nothing is returned, so that’s probably where to look for now.

Nephtis | 2020-09-30 05:41

:bust_in_silhouette: Reply From: Nephtis

I think the problem is that I’m using an AnimationTree with an AnimationNodeStateMachinePlayback to trigger the animation via travel(), so even though it refers to an AnimationPlayer’s animation, the AnimationPlayer isn’t actually “playing” it itself, so its current animation ends up being null, meaning I can’t call e.g. stop(false).

The docs for AnimationTree say:

Note: When linked with an AnimationPlayer, several properties and methods of the corresponding AnimationPlayer will not function as expected. Playback and transitions should be handled using only the AnimationTree and its constituent AnimationNode(s). The AnimationPlayer node should be used solely for adding, deleting, and editing animations.

I will change the way my animation system works.

I ran into this same issue after I had already built a fairly complex state machine.

Fortunately, I was able to achieve the pausing behavior I wanted by simply nesting the AnimationNodeStateMachine inside a AnimationNodeBlendTree and hooking a AnimationNodeTimeScale inbetween my state machine and the output.

blend tree example

You can then pause/resume by calling anim_tree.set('parameters/time_scale/scale', 0) on the AnimationTree. 0 pauses and 1 resumes.

dinolaser | 2020-10-30 15:21