ESC prefab instantiating is breaking the prefab's hierarchy

In Unity ECS 1.4.2, I try to instantiate Entities in form of prefabs.

This is done by baking the prefabs as entities into a component, whose data is then used by a system to instantiate.

When I manualy drag the prefab into the game, it’s fine, parent and child relations are as they should be.
But when instantiated by the system, it breaks it in two.

I have no idea what makes it decide to divide the prefab in two.
It can’t be of the fact that each gameobject has its own baker, as the gameobjects would have then divided into independent entities, with no parent and child relation at all.
I tried to bake them all in one baker, but get InvalidOperationException Error, as the baking pipeline only permit to modify entities that has its own authoring Gameobject.
That makes gathering them in a LinkedEntityGroup impossible.
I then tried to keep their indivual baker scripts, and add AdditionalEntityParent component to each entity, with reference to the parent gameobject, but that didn’t work either.

I have no idea what to do, to make Unity stop spawning a divided prefab, and why it considered an entity in the prefab as a root parent when it is not.

I can share a screenshot of my failed RootBaker script that should gather them all in one LinkedEntityGroup:

Prefabs automatically add LinkedEntityGroup for the hierarchy on their own, which means with you adding it, you are probably fighting that system and making Unity confused. For subscene entities, you can force the same behavior using the LinkedEntityGroupAuthoring component.

This is correct, but since it seemingly didn’t gather them in a LinkedEntity automatically in the first place, I figured I needed to do it manually myself. The rootbaker came after the failure of the automatically LinkedEntityGroup.

I will try to replace AdditionalEntityParent with LinkedEntityGroups instead.

Hasen’t worked either with the LinkedEntityGroupAuthoring component.

After that, I tried to build up the prefab from the ground up, which didn’t work either, so I have now started a whole new project, and made that as the first thing.

Now it does spawn properly, so something has messed it up. I will add everything back in slowly, and see where it messes up.

Did you try deleting the whole Library folder? Also the SceneDependencyCache folder. Might be a problem with caching.

Didn’t do it either, but thanks for the suggestion.

It must be from something I updated. A tiny detail probally somewhere.

But with the clean slate it works for now. And I keep an eye out for when it breaks again

I am having a similar problem and I managed to figure out that the Unity Physics package was the culprit. I uninstalled that and my prefab entity parenting magically worked again. I have no idea why nor how to make it work with Unity Physics installed tho :ㅤ/

Edit: I figured it out. The children had colliders on them and the physics system was converting them to physics entities (thus unparenting them). I fixed it by adding a Physics body (set to kinematic) to the parent and replacing all colliders with Physic Shapes (from Unity Physics>Samples>Custom Physics Authoring).