From 94f6d289a86318ed21cad8938511b0a5d0f6efca Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 14 Aug 2023 14:15:01 +0200 Subject: [PATCH] Allow BTPlayAnimation with `animation_name` empty to resume playback after pause --- bt/actions/bt_play_animation.cpp | 16 ++++++++-------- doc_classes/BTPlayAnimation.xml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bt/actions/bt_play_animation.cpp b/bt/actions/bt_play_animation.cpp index d0d0a50..c37e0d1 100644 --- a/bt/actions/bt_play_animation.cpp +++ b/bt/actions/bt_play_animation.cpp @@ -65,18 +65,16 @@ String BTPlayAnimation::get_configuration_warning() const { warning += "AnimationPlayer blackboard variable is not set.\n"; } } - if (animation_name == StringName()) { - warning += "Animation Name is not set.\n"; + if (animation_name == StringName() && await_completion > 0.0) { + warning += "Animation Name is required in order to wait for the animation to finish.\n"; } return warning; } String BTPlayAnimation::_generate_name() const { - if (animation_name == StringName() || animation_player_param.is_null()) { - return "PlayAnimation ???"; - } - return vformat("PlayAnimation \"%s\"", animation_name) + + return "PlayAnimation" + + (animation_name != StringName() ? vformat(" \"%s\"", animation_name) : "") + (blend >= 0.0 ? vformat(" blend: %ss", Math::snapped(blend, 0.001)) : "") + (speed != 1.0 ? vformat(" speed: %s", Math::snapped(speed, 0.001)) : "") + (from_end != false ? vformat(" from_end: %s", from_end) : "") + @@ -88,8 +86,10 @@ void BTPlayAnimation::_setup() { ERR_FAIL_COND_MSG(animation_player_param.is_null(), "BTPlayAnimation: AnimationPlayer parameter is not set."); animation_player = Object::cast_to(animation_player_param->get_value(get_agent(), get_blackboard())); ERR_FAIL_COND_MSG(animation_player == nullptr, "BTPlayAnimation: Failed to get AnimationPlayer."); - ERR_FAIL_COND_MSG(animation_name == StringName(), "BTPlayAnimation: Animation name is not set."); - ERR_FAIL_COND_MSG(!animation_player->has_animation(animation_name), vformat("BTPlayAnimation: Animation not found: %s", animation_name)); + ERR_FAIL_COND_MSG(animation_name != StringName() && !animation_player->has_animation(animation_name), vformat("BTPlayAnimation: Animation not found: %s", animation_name)); + if (animation_name == StringName() && await_completion > 0.0) { + WARN_PRINT("BTPlayAnimation: Animation Name is required in order to wait for the animation to finish."); + } setup_failed = false; } diff --git a/doc_classes/BTPlayAnimation.xml b/doc_classes/BTPlayAnimation.xml index c082822..f4f20dd 100644 --- a/doc_classes/BTPlayAnimation.xml +++ b/doc_classes/BTPlayAnimation.xml @@ -13,7 +13,7 @@ - Animation's key within the AnimationPlayer node. + Animation's key within the AnimationPlayer node. If empty, BTPlayAnimation will resume the last played animation if [class AnimationPlayer] was paused. Parameter that specifies the AnimationPlayer node.