diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 72b31170ea9..4bb44313b00 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -164,6 +164,7 @@ Ref Tween::tween_subtween(const Ref &p_subtween) { if (tweener->subtween->parent_tree != nullptr) { tweener->subtween->parent_tree->remove_tween(tweener->subtween); } + subtweens.push_back(p_subtween); append(tweener); return tweener; } @@ -200,6 +201,11 @@ void Tween::kill() { running = false; // For the sake of is_running(). valid = false; dead = true; + + // Kill all subtweens of this tween. + for (Ref &st : subtweens) { + st->kill(); + } } bool Tween::is_running() { diff --git a/scene/animation/tween.h b/scene/animation/tween.h index ef82be9a2da..a4d94cfd2f2 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -112,6 +112,7 @@ private: SceneTree *parent_tree = nullptr; LocalVector>> tweeners; + LocalVector> subtweens; double total_time = 0; int current_step = -1; int loops = 1;