diff --git a/src/framework/components/collision/system.js b/src/framework/components/collision/system.js index b7b29280118..fe456590f40 100644 --- a/src/framework/components/collision/system.js +++ b/src/framework/components/collision/system.js @@ -83,8 +83,7 @@ class CollisionSystemImpl { component._compoundParent.entity.rigidbody.activate(); } - Ammo.destroy(data.shape); - data.shape = null; + this.destroyShape(data); } data.shape = this.createPhysicalShape(component.entity, data); @@ -156,6 +155,13 @@ class CollisionSystemImpl { } } + destroyShape(data) { + if (data.shape) { + Ammo.destroy(data.shape); + data.shape = null; + } + } + beforeRemove(entity, component) { if (component.data.shape) { if (component._compoundParent && !component._compoundParent.entity._destroying) { @@ -167,8 +173,7 @@ class CollisionSystemImpl { component._compoundParent = null; - Ammo.destroy(component.data.shape); - component.data.shape = null; + this.destroyShape(component.data); } } @@ -514,11 +519,6 @@ class CollisionMeshSystemImpl extends CollisionSystemImpl { Ammo.destroy(data.shape); data.shape = null; } - - remove(entity, data) { - this.destroyShape(data); - super.remove(entity, data); - } } // Compound Collision System