Check if animations and callbacks in Tween are finished

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Aaron
:warning: Old Version Published before Godot 3 was released.

What is the best way to tell when all of a Tween’s animations, including all callbacks, are finished?

I want to have logic like this:

func _fixed_process(delta)
    if not_animating():
        if Input.is_action_pressed("do_move"):
            tween.interpolate_property(mobile, "transform/pos", mobile.get_pos(), new_pos, ANIM_TIME, ...)
            tween.interpolate_callback(object, ANIM_TIME, "mobile_moved")

I want to wait until all animations are finished before responding to input. So I’m wondering what to put in not_animating()

tween.is_active() doesn’t seem to be the method to check. It apparently returns true as long as any animations are attached to the tween, even if enough time has passed for all the animations to run.

I’ve therefore tried comparing tween.tell() with tween.get_runtime(). But when I do tween.tell() < tween.get_runtime() I miss the ending object.mobile_moved() callback. But tween.tell() doesn’t change after it reaches the same value as tween.get_runtime(), so with tween.tell() < tween.get_runtime() I can’t distinguish between the tween being finished and the tween being at the very end.

Why not have a boolean variable and just change it (maybe even via “set”) with interpolate_callback?

Bojidar Marinov | 2016-03-20 13:39

This is what I ended up doing, having an _is_animating variable and calling tween.interpolate_callback(self, tween.get_runtime(), "_stop_animating") that sets _is_animating to false and also calls tween.remove_all(). Too bad there doesn’t seem to be anything built into the Tween class.

Aaron | 2016-03-20 17:51

Did you find any more elegant solution to this? I’m struggling with the same.

Samuel Pedrajas | 2017-06-02 18:27

No. Having a separate boolean variable that’s set with a final callback registered with the tween seems to be the only option.

Tweens do have a tween_complete signal, that’s emitted for individual actions registered with the tween. But it’s apparently not sent for callbacks registered with interpolate_callback.

Since I wrote this question I’ve found it easier to avoid using interpolate_callback and only use interpolate_property combined with the tween_complete signal, as the Tween class seems unfinished otherwise.

Aaron | 2017-12-05 22:34