I am foregoing the baking process and am creating and managing my entities at runtime to facilitate a hybrid approach. This is serving me well so far, but like the title says, whenever I give an entity the Parent component it automatically un-parents itself in the following frame. The parent-child relationship shows correctly before then, adding the Child buffer to the parent as expected, and appearing correct in the Hierarchy view.
I thought it might be because I gave both parent and child a collider and rigidbody, but it even happens on plain entities. Does anyone know what might be causing this?
I’m not in Unity 6 but I’m also using Entities 1.2. May I ask for the code that managed your entity (where you add components, the Parent component in particular)?
Did you test the while loop in the BuildChildEntityMap? It might cause a bug because it’s not changed inside the loop. This can be converted to a better recursion method instead.
I don’t have a safe scene to test this but, I quickly dropped it in a scene and immediately received an error with the entityManager. You don’t need to cache the EntityManager for your use case.
The building of the entities is working as expected. If I pause the editor before hitting Play, I can see all the right entities, with all of their correct components and relationships. The problem is that the parent-child relationship is immediately broken the following frame, and I can’t for the life of me figure out why.
You’re right on the caching though; made it a convenience getter instead. (I’ll still need it after Awake() as the hosts are pooled)
I exposed some methods with identical names in my EntityHost MB to more easily allow my runtime “bakers” to add components. So good catch, but nope!