diff --git a/doc/classes/Tween.xml b/doc/classes/Tween.xml index 544ccc7746..d1d253cf18 100644 --- a/doc/classes/Tween.xml +++ b/doc/classes/Tween.xml @@ -144,6 +144,12 @@ [b]Note:[/b] As it results from accumulating frame deltas, the time returned after the [Tween] has finished animating will be slightly greater than the actual [Tween] duration. + + + + Returns [code]true[/code] if any [Tweener] has been added to the [Tween] and the [Tween] is valid. Useful when tweeners are added dynamically and the tween can end up empty. Killing an empty tween before it starts will prevent errors. + + diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 9e0d7a2223..71f3729ca1 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -218,6 +218,10 @@ void Tween::kill() { } } +bool Tween::has_tweeners() const { + return !tweeners.is_empty(); +} + bool Tween::is_running() { return running; } @@ -493,6 +497,7 @@ void Tween::_bind_methods() { ClassDB::bind_method(D_METHOD("kill"), &Tween::kill); ClassDB::bind_method(D_METHOD("get_total_elapsed_time"), &Tween::get_total_time); + ClassDB::bind_method(D_METHOD("has_tweeners"), &Tween::has_tweeners); ClassDB::bind_method(D_METHOD("is_running"), &Tween::is_running); ClassDB::bind_method(D_METHOD("is_valid"), &Tween::is_valid); ClassDB::bind_method(D_METHOD("bind_node", "node"), &Tween::bind_node); diff --git a/scene/animation/tween.h b/scene/animation/tween.h index bb3ce23476..a8a7c3acc8 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -159,6 +159,7 @@ public: void play(); void kill(); + bool has_tweeners() const; bool is_running(); bool is_valid(); void clear();