n5ro/aframe-physics-system

removeChild fails to remove all bodies from an entity

pookage opened this issue · 0 comments

If I try to removeChild(element) where element has both a body and a shape, I get the following error:

Uncaught TypeError: Cannot read property 'mass' of undefined

For example (in order to get a collision mesh larger than the geometry):

<a-box
    id="example" 
    height="0.9" width="0.9" depth="0.9"
    body="type: static; shape: none;"
    shape: "box; halfExtents: 0.5 0.5 0.5"
></a-box>

and I later do:

const box = document.getElementById("example");
box.parentElement.removeChild(box)

the above error will occur. This error doesn't happen if only a body is declared:

<a-box
    id="example" 
    height="0.9" width="0.9" depth="0.9"
    body="type: static; shape: box;"
></a-box>

but then the collision mesh is the same size as the box, so we lose that functionality...