Repository: godotengine/godot
File: editor/inspector/editor_properties.cpp (C++)

Code before:
	if (!base_node) {
		base_node = Object::cast_to<Node>(InspectorDock::get_inspector_singleton()->get_edited_object());
	}
	if (!base_node) {
		// Try a base node within history.
		if (EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() > 0) {
			Object *base = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(0));
			if (base) {
				base_node = Object::cast_to<Node>(base);
			}
		}
	}

	if (!use_path_from_scene_root) {
		return base_node;
	}

	if (get_edited_object()->has_method("get_root_path")) {
		return Object::cast_to<Node>(get_edited_object()->call("get_root_path"));
	}

	if (!base_node) {
		return nullptr; // Editing external resources.
	}

	if (!base_node->get_scene_file_path().is_empty()) {
		return base_node; // Known scene root.
	}

	base_node = base_node->get_owner();
	if (base_node) {
		return base_node; // Node in known scene.
	}

	return get_tree()->get_edited_scene_root(); // Treat as a node in the main scene.
}

EditorPropertyNodePath::EditorPropertyNodePath() {
	HBoxContainer *hbc = memnew(HBoxContainer);
	hbc->add_theme_constant_override("separation", 0);
	add_child(hbc);
	assign = memnew(Button);
	assign->set_accessibility_name(TTRC("Assign Node"));
	assign->set_flat(true);
	assign->set_theme_type_variation(SNAME("EditorInspectorButton"));
	assign->set_h_size_flags(SIZE_EXPAND_FILL);
	assign->set_clip_text(true);
	assign->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
	assign->set_expand_icon(true);
	assign->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyNodePath::_node_assign));
	assign->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyNodePath::_assign_draw));

Review comment (suggestion):
```suggestion
	if (base_node->is_instance()) {
```

Code after:
		// Try a base node within history.
		if (EditorNode::get_singleton()->get_editor_selection_history()->get_path_size() > 0) {
			Object *base = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_path_object(0));
			if (base) {
				base_node = Object::cast_to<Node>(base);
			}
		}
	}

	if (!use_path_from_scene_root) {
		return base_node;
	}

	if (get_edited_object()->has_method("get_root_path")) {
		return Object::cast_to<Node>(get_edited_object()->call("get_root_path"));
	}

	if (!base_node) {
		return nullptr; // Editing external resources.
	}

	if (base_node->is_instance()) {
		return base_node; // Known scene root.
	}

	base_node = base_node->get_owner();
	if (base_node) {
		return base_node; // Node in known scene.
	}

	return get_tree()->get_edited_scene_root(); // Treat as a node in the main scene.
}

EditorPropertyNodePath::EditorPropertyNodePath() {
	HBoxContainer *hbc = memnew(HBoxContainer);
	hbc->add_theme_constant_override("separation", 0);
	add_child(hbc);
	assign = memnew(Button);
	assign->set_accessibility_name(TTRC("Assign Node"));
	assign->set_flat(true);
	assign->set_theme_type_variation(SNAME("EditorInspectorButton"));
	assign->set_h_size_flags(SIZE_EXPAND_FILL);
	assign->set_clip_text(true);
	assign->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
	assign->set_expand_icon(true);
	assign->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyNodePath::_node_assign));
	assign->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyNodePath::_assign_draw));
	SET_DRAG_FORWARDING_CD(assign, EditorPropertyNodePath);
	hbc->add_child(assign);

	menu = memnew(MenuButton);