diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 5cc2ab0b56f..7f948f26fd4 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -260,6 +260,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, r_includes_current = false; List<_RayResult> results; + Vector subscenes = Vector(); for (int i = 0; i < instances.size(); i++) { @@ -275,11 +276,18 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, Ref seg = spat->get_gizmo(); - if (!seg.is_valid()) - continue; + if (!seg.is_valid() || found_gizmos.has(seg)){ + Node *subscene_candidate = spat; + while (subscene_candidate->get_owner() != editor->get_edited_scene()) + subscene_candidate = subscene_candidate->get_owner(); + + spat = subscene_candidate->cast_to(); + if (spat && (spat->get_filename() != "")) + subscenes.push_back(spat); - if (found_gizmos.has(seg)) continue; + } + found_gizmos.insert(seg); Vector3 point; @@ -305,6 +313,24 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, res.handle = handle; results.push_back(res); } + for (int idx_subscene = 0; idx_subscene < subscenes.size(); idx_subscene++) { + + Spatial *subscene = subscenes.get(idx_subscene); + float dist = ray.cross(subscene->get_global_transform().origin - pos).length(); + + if ((dist < 0) || (dist > 1.2)) + continue; + + if (editor_selection->is_selected(subscene)) + r_includes_current = true; + + _RayResult res; + res.item = subscene; + res.depth = dist; + res.handle = -1; + results.push_back(res); + } + if (results.empty()) return 0;