From d06d5700c07ca73d088c3738bb47f11fd85426c6 Mon Sep 17 00:00:00 2001 From: vaner-org Date: Thu, 23 Oct 2025 02:25:39 +0530 Subject: [PATCH] Improved validation for adding transitions to StateMachine --- .../animation_state_machine_editor.cpp | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/editor/animation/animation_state_machine_editor.cpp b/editor/animation/animation_state_machine_editor.cpp index bb3ea057f7d..d289ef2f868 100644 --- a/editor/animation/animation_state_machine_editor.cpp +++ b/editor/animation/animation_state_machine_editor.cpp @@ -1010,8 +1010,20 @@ void AnimationNodeStateMachineEditor::_connect_to(int p_index) { void AnimationNodeStateMachineEditor::_add_transition(const bool p_nested_action) { if (connecting_from != StringName() && connecting_to_node != StringName()) { + if (connecting_to_node == SceneStringName(Start)) { + EditorNode::get_singleton()->show_warning(TTR("Cannot transition to \"Start\"!")); + connecting = false; + return; + } + + if (connecting_from == SceneStringName(End)) { + EditorNode::get_singleton()->show_warning(TTR("Cannot transition from \"End\"!")); + connecting = false; + return; + } + if (state_machine->has_transition(connecting_from, connecting_to_node)) { - EditorNode::get_singleton()->show_warning("Transition exists!"); + EditorNode::get_singleton()->show_warning(TTR("Transition already exists!")); connecting = false; return; } @@ -1039,11 +1051,13 @@ void AnimationNodeStateMachineEditor::_add_transition(const bool p_nested_action _select_transition(connecting_from, connecting_to_node); - if (!state_machine->is_transition_across_group(selected_transition_index)) { - EditorNode::get_singleton()->push_item(tr.ptr(), "", true); - } else { - EditorNode::get_singleton()->push_item(tr.ptr(), "", true); - EditorNode::get_singleton()->push_item(nullptr, "", true); + if (selected_transition_index >= 0) { + if (!state_machine->is_transition_across_group(selected_transition_index)) { + EditorNode::get_singleton()->push_item(tr.ptr(), "", true); + } else { + EditorNode::get_singleton()->push_item(tr.ptr(), "", true); + EditorNode::get_singleton()->push_item(nullptr, "", true); + } } _update_mode(); }