diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 2a851eee..1de50688 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -245,11 +245,15 @@ namespace Nuake { } } - m_IsViewportFocused = ImGui::IsWindowFocused(); - if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing()) + if (m_IsHoveringViewport && !m_IsViewportFocused && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_2)) { ImGui::FocusWindow(ImGui::GetCurrentWindow()); + } + m_IsViewportFocused = ImGui::IsWindowFocused(); + + if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing()) + { const auto windowPosNuake = Vector2(windowPos.x, windowPos.y); auto& gbuffer = Engine::GetCurrentScene()->m_SceneRenderer->GetGBuffer(); auto pixelPos = Input::GetMousePosition() - windowPosNuake; @@ -259,7 +263,11 @@ namespace Nuake { if (const int result = gbuffer.ReadPixel(3, pixelPos); result > 0) { - Selection = EditorSelection(Entity{ (entt::entity)(result - 1), Engine::GetCurrentScene().get()}); + auto& ent = Entity{ (entt::entity)(result - 1), Engine::GetCurrentScene().get() }; + if (ent.IsValid()) + { + Selection = EditorSelection(ent); + } } else { diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index a5674899..da4ac1b8 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -87,6 +87,11 @@ void EditorSelectionPanel::DrawNone() void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) { + if (!entity.IsValid()) + { + return; + } + DrawAddComponentMenu(entity); // Draw each component properties panels.