diff --git a/SDK/include/NDK/Components/DebugComponent.hpp b/SDK/include/NDK/Components/DebugComponent.hpp index 0777a9812..e0993d26d 100644 --- a/SDK/include/NDK/Components/DebugComponent.hpp +++ b/SDK/include/NDK/Components/DebugComponent.hpp @@ -41,6 +41,7 @@ namespace Ndk constexpr DebugDrawFlags DebugDraw_None = 0; class DebugComponent; + class GraphicsComponent; using DebugComponentHandle = Nz::ObjectHandle; @@ -65,8 +66,14 @@ namespace Ndk static ComponentIndex componentIndex; private: + void DetachDebugRenderables(GraphicsComponent& gfxComponent); + inline const Nz::InstancedRenderableRef& GetDebugRenderable(DebugDraw option) const; inline DebugDrawFlags GetEnabledFlags() const; + + void OnComponentDetached(BaseComponent& component) override; + void OnDetached() override; + inline void UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable); inline void UpdateEnabledFlags(DebugDrawFlags flags); diff --git a/SDK/src/NDK/Components/DebugComponent.cpp b/SDK/src/NDK/Components/DebugComponent.cpp index 6c8ab9f1c..604e1d143 100644 --- a/SDK/src/NDK/Components/DebugComponent.cpp +++ b/SDK/src/NDK/Components/DebugComponent.cpp @@ -3,8 +3,33 @@ // For conditions of distribution and use, see copyright notice in Prerequisites.hpp #include +#include namespace Ndk { + void DebugComponent::DetachDebugRenderables(GraphicsComponent& gfxComponent) + { + for (auto& renderable : m_debugRenderables) + { + if (renderable) + { + gfxComponent.Detach(renderable); + renderable.Reset(); + } + } + } + + void DebugComponent::OnComponentDetached(BaseComponent& component) + { + if (IsComponent(component)) + DetachDebugRenderables(static_cast(component)); + } + + void DebugComponent::OnDetached() + { + if (m_entity->HasComponent()) + DetachDebugRenderables(m_entity->GetComponent()); + } + ComponentIndex DebugComponent::componentIndex; }