Fixes #4. If the entity already has a parent, detach it first.