diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index 392cbbeb..b876f5b0 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -310,6 +310,27 @@ namespace SHADE SHEventManager::BroadcastEvent(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); } + void SHSceneGraph::SetActive(EntityID entityID, bool isActive) noexcept + { + //////////////////////////////////////// + // Error handling + if (!SHEntityManager::IsValidEID(entityID)) + { + SHLOG_ERROR("Entity {} is invalid!", entityID) + return; + } + + const auto NODE_ITER = entityNodeMap.find(entityID); + if (NODE_ITER == entityNodeMap.end()) + { + SHLOG_ERROR("Entity {} cannot be found in the scene!", entityID) + return; + } + //////////////////////////////////////// + + NODE_ITER->second->SetActive(isActive); + } + /*-----------------------------------------------------------------------------------*/ /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.h b/SHADE_Engine/src/Scene/SHSceneGraph.h index 68e13b69..3285fc6f 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.h +++ b/SHADE_Engine/src/Scene/SHSceneGraph.h @@ -68,6 +68,8 @@ namespace SHADE void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept; void SetParent (EntityID entityID, EntityID newParent) noexcept; + void SetActive (EntityID entityID, bool isActive) noexcept; + /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Scene/SHSceneNode.cpp b/SHADE_Engine/src/Scene/SHSceneNode.cpp index 42046df4..2b45b037 100644 --- a/SHADE_Engine/src/Scene/SHSceneNode.cpp +++ b/SHADE_Engine/src/Scene/SHSceneNode.cpp @@ -145,6 +145,10 @@ namespace SHADE active = newActiveState; isActiveInHierarchy = newActiveState; + // Set the entity's active state + // TODO(Daniel / Diren): Sync it based on active in hierarchy or active state. + SHEntityManager::GetEntityByID(entityID)->SetActive(active); + // Recurse down the children to set the active in hierarchy state recursiveSetActiveInHierarchy(active, children); } diff --git a/SHADE_Managed/src/Engine/GameObject.cxx b/SHADE_Managed/src/Engine/GameObject.cxx index 3557e8f1..0e03a643 100644 --- a/SHADE_Managed/src/Engine/GameObject.cxx +++ b/SHADE_Managed/src/Engine/GameObject.cxx @@ -76,7 +76,13 @@ namespace SHADE { if (!valid) throw gcnew System::NullReferenceException(); - return GetNativeEntity().GetActive(); + auto node = SHSceneManager::GetCurrentSceneGraph().GetNode(GetEntity()); + if (!node) + { + Debug::LogWarning("Attempting to access a GameObject's Active state which does not exist. Assuming inactive."); + return false; + } + return node->IsActive(); } bool GameObject::IsActiveInHierarchy::get() { @@ -88,7 +94,7 @@ namespace SHADE Debug::LogWarning("Attempting to access a GameObject's ActiveInHierarchy state which does not exist. Assuming inactive."); return false; } - return node->IsActive(); + return node->IsActiveInHierarchy(); } Entity GameObject::EntityId::get() { @@ -148,7 +154,8 @@ namespace SHADE { if (!valid) throw gcnew System::NullReferenceException(); - GetNativeEntity().SetActive(active); + + SHSceneManager::GetCurrentSceneGraph().SetActive(GetEntity(), active); } /*---------------------------------------------------------------------------------*/