@@ -852,6 +852,26 @@ void Editor::DestroyEntityInternal(ZEntityRef p_Entity, std::optional<std::strin
852852 const auto s_NodeToRemove = s_EntityIter->second ;
853853 m_CachedEntityTreeMap.erase (s_EntityIter);
854854
855+ // If a child of this node is selected, deselect it (non-recursive).
856+ std::queue<std::shared_ptr<EntityTreeNode>> s_ChildrenQueue;
857+
858+ for (auto & s_Child: s_NodeToRemove->Children ) {
859+ s_ChildrenQueue.push (s_Child.second );
860+ }
861+
862+ while (!s_ChildrenQueue.empty ()) {
863+ if (m_SelectedEntity == s_ChildrenQueue.front ()->Entity ) {
864+ m_SelectedEntity = {};
865+ break ;
866+ }
867+
868+ for (auto & s_Child: s_ChildrenQueue.front ()->Children ) {
869+ s_ChildrenQueue.push (s_Child.second );
870+ }
871+
872+ s_ChildrenQueue.pop ();
873+ }
874+
855875 // Remove it from the children of all its parents.
856876 for (auto & s_Parent: s_NodeToRemove->Parents ) {
857877 for (auto it = s_Parent->Children .begin (); it != s_Parent->Children .end ();) {
@@ -895,6 +915,26 @@ void Editor::DestroyEntityNodeInternal(
895915 }
896916 }
897917
918+ // If a child of this node is selected, deselect it (non-recursive).
919+ std::queue<std::shared_ptr<EntityTreeNode>> s_ChildrenQueue;
920+
921+ for (auto & s_Child: p_NodeToRemove->Children ) {
922+ s_ChildrenQueue.push (s_Child.second );
923+ }
924+
925+ while (!s_ChildrenQueue.empty ()) {
926+ if (m_SelectedEntity == s_ChildrenQueue.front ()->Entity ) {
927+ m_SelectedEntity = {};
928+ break ;
929+ }
930+
931+ for (auto & s_Child: s_ChildrenQueue.front ()->Children ) {
932+ s_ChildrenQueue.push (s_Child.second );
933+ }
934+
935+ s_ChildrenQueue.pop ();
936+ }
937+
898938 for (auto & s_Parent: p_NodeToRemove->Parents ) {
899939 for (auto it = s_Parent->Children .begin (); it != s_Parent->Children .end ();) {
900940 if (it->second == p_NodeToRemove) {
0 commit comments