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.
+7 votes

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")
            tween.start()

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.

in Engine by (291 points)
edited by

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

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.

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

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.

Please log in or register to answer this question.

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.