From 6e8c22d5987622b932d8722dba3463e02207ed1c Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 11 Nov 2024 10:23:08 +0100 Subject: [PATCH] Clean up & strengthen code --- blackboard/blackboard_plan.cpp | 2 +- editor/editor_property_property_path.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index bc054d4..333fa53 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -122,7 +122,7 @@ bool BlackboardPlan::_get(const StringName &p_name, Variant &r_ret) const { if (!edited_node) { edited_node = SCENE_TREE()->get_edited_scene_root(); } - Node *bound_node = edited_node->get_node_or_null(binding); + Node *bound_node = edited_node ? edited_node->get_node_or_null(binding) : nullptr; String shortened_path; if (bound_node) { diff --git a/editor/editor_property_property_path.cpp b/editor/editor_property_property_path.cpp index cc31f55..6d6de88 100644 --- a/editor/editor_property_property_path.cpp +++ b/editor/editor_property_property_path.cpp @@ -48,12 +48,15 @@ Node *_get_base_node(Object *p_edited_object, SceneTree *p_scene_tree) { } // unnamed namespace Node *EditorPropertyPropertyPath::_get_selected_node() { + ERR_FAIL_NULL_V(get_edited_object(), nullptr); + NodePath path = get_edited_object()->get(get_edited_property()); if (path.is_empty()) { return nullptr; } Node *base_node = _get_base_node(get_edited_object(), get_tree()); + ERR_FAIL_NULL_V(base_node, nullptr); Node *selected_node = base_node->get_node_or_null(path); return selected_node; } @@ -96,9 +99,9 @@ void EditorPropertyPropertyPath::_property_selected(const NodePath &p_property_p } Node *base_node = _get_base_node(get_edited_object(), get_tree()); ERR_FAIL_NULL(base_node); - Node *chosen_node = get_tree()->get_edited_scene_root()->get_node_or_null(p_node_path); - ERR_FAIL_NULL(chosen_node); - NodePath path = String(base_node->get_path_to(chosen_node)) + String(p_property_path); + Node *selected_node = get_tree()->get_edited_scene_root()->get_node_or_null(p_node_path); + ERR_FAIL_NULL(selected_node); + NodePath path = String(base_node->get_path_to(selected_node)) + String(p_property_path); emit_changed(get_edited_property(), path); update_property(); @@ -217,6 +220,7 @@ bool EditorInspectorPluginPropertyPath::_parse_property(Object *p_object, const EditorPropertyPropertyPath *ed = memnew(EditorPropertyPropertyPath); + // Convert the hint text to an array of valid types. PackedInt32Array valid_types; PackedStringArray type_specifiers = p_hint_text.split(","); for (const String &t : type_specifiers) {