From b41eaad788294a1a22925c86712a085d308ca176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 28 Oct 2023 21:48:56 +0200 Subject: [PATCH] Disposable Rigidbody2D --- GlitchyEngine/src/World/Components/Components.bf | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/GlitchyEngine/src/World/Components/Components.bf b/GlitchyEngine/src/World/Components/Components.bf index 142e8e2..af18316 100644 --- a/GlitchyEngine/src/World/Components/Components.bf +++ b/GlitchyEngine/src/World/Components/Components.bf @@ -375,7 +375,7 @@ namespace GlitchyEngine.World public SceneLight SceneLight; } - struct Rigidbody2DComponent + struct Rigidbody2DComponent : IDisposableComponent { public enum BodyType { Static = 0, Dynamic = 1, Kinematic = 2 } @@ -497,6 +497,12 @@ namespace GlitchyEngine.World if (RuntimeBody != null) Box2D.Body.SetAngularVelocity(RuntimeBody, velocity); } + + public void Dispose() + { + if (RuntimeBody != null && ScriptEngine.Context?.[Friend]_physicsWorld2D != null) + Box2D.World.DestroyBody(ScriptEngine.Context.[Friend]_physicsWorld2D, RuntimeBody); + } } /*struct InternalBug