I have a GameObject prefab that consists of a parent and 2 children. The parent only has a transform. The children both have mesh renderers for visuals. When I play, the children do not appear to be “children” of the parent entity. They are showing up outside the parent in the Entities Hierarchy. This is causing changes to the parents LocalTransform to not affect the childrens LocalTransforms. However, If I add a Mesh Filter/Renderer/Collider to the Parent GameObject, it suddenly starts working as expected (children entities are showing as children (nested) and their transforms are being affected).
Even if I add a LinkedEntityGroupAuthoring to the Parent, it still does not work.
Is this entity in a subscene and not a prefab? Entities in subscenes are optimized and have their hierarchy stripped if Unity thinks they are static. You need your baker to mark it with the correct TransformFlags to avoid this.
It is in both. The prefab is being referenced in a Directory GameObject in the subscene. Here is some sample code of the setup.
Note: The ‘MyPrefab’ GameObject is the prefab with the children. It is not directly in the subscene. There is a ‘MyDirectory’ GameObject in the subscene, with the following authoring script on it.
class MyPrefabAuthoring : MonoBehaviour {
class Baker : Baker< MyPrefabAuthoring > {
override void Bake(MyPrefabAuthoring authoring) {
}
}
}
class MyDirectoryAuthoring : MonoBehaviour {
public GameObject MyPrefab;
class Baker : Baker< MyDirectoryAuthoring > {
override void Bake(MyDirectoryAuthoring authoring) {
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new MyDirectory {
MyPrefabEntity = GetEntity(MyPrefab, TransformUsageFlags.Dynamic)
});
}
}
}
struct MyDirectory : IComponentData {
Entity MyPrefabEntity
}
What TransformFlags should be used? Do I need to do special linking in the MyPrefabAuthoring?
Hi. I tried this code with the prefab that has an empty gameObject as parent and a cube as child.
And then instantiate the MyPrefabEntity in the MyDirectory in a system. the cube did appeared as a child of its parent. I’m not sure what makes the result different. TransformUsageFlags.Dynamic should be enough to tell unity that there is a parent-child relation of the transforms between two entities.
And I wonder what MyPrefabAuthoring is used for, because you bake the prefab in MyDirectoryAuthoring