How to change parent for an entity

Hi

I am having some strange issues coming from the ParentSystem while i am trying to change parents for some entities.
InvalidOperationException: Child entity not in parent

What is the best way to change the parent of an entity and remove a parent completely?

At the moment this is what i am doing

A) set Parent and PreviousParent data to PARENT B
B) Rebuild Child and LinkedEntityGroup buffers for both PARENT A and PARENT B

This is how i remove entities from a Parent

 Game.Instance.EntityWorld.EntityManager.RemoveComponent<Parent>(localEntity);
        Game.Instance.EntityWorld.EntityManager.RemoveComponent<LocalToParent>(localEntity);
        Game.Instance.EntityWorld.EntityManager.RemoveComponent<PreviousParent>(localEntity);

Rebuild Child and LinkedEntityGroup buffers

this is where it crashes in parentsystem as well

Don’t touch PreviousParent and Child buffers. Those are system state and you should let the system clean those up for you.

1 Like

ok thank you!
so only update the Parent data and the LinkedEntityGroup buffer