Baking system is unable to locate a Component that was added using GetEntity(Prefab)

In my program, I need to create an Entity through a configured prefab. This prefab contains an Authoring component。

public struct PrefabComponent : IComponentData
{
    public int Value;
}

public class PrefabAuthoring : MonoBehaviour
{

    public class Baker : Baker<PrefabAuthoring >
    {
        public override void Bake(PrefabAuthoring authoring)
        {
            var entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent(entity, new PrefabComponent () {Value = 0});
        }
    }
}

This Prefab is utilized within the Baker of another Authoring component.

public struct EntityPrefabComponent : IComponentData
{
    public Entity Value;
}

public class GetPrefabAuthoring : MonoBehaviour
{
    public GameObject Prefab;

    public class Baker : Baker<GetPrefabAuthoring>
    {
        public override void Bake(GetPrefabAuthoring authoring)
        {
            // Register the Prefab in the Baker
            var entityPrefab = GetEntity(authoring.Prefab, TransformUsageFlags.Dynamic);
            // Add the Entity reference to a component for instantiation later
            var entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent(entity, new EntityPrefabComponent() {Value = entityPrefab});
        }
    }
}

However, the PrefabComponent cannot be found within the Baking System.

    [WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
    public partial struct MyBakingSystem : ISystem
    {
        public void OnCreate(ref SystemState state)
        {
            Unity.Logging.Log.Info("MyBakingSystem .OnCreate");
            state.RequireForUpdate<PrefabComponent>();
        }

        public void OnUpdate(ref SystemState state)
        {
           // The code here is not being executed.
            Unity.Logging.Log.Info("MyBakingSystem .OnUpdate");

        }
    }

May I ask how to solve this ?

RequireForUpdate doesn’t include prefabs, you should create your own query that specifies EntityQueryOptions.IncludePrefab, and do the same for any other time you search for those entities (foreach, other EntityQuery).

@Spy-Master Many thanks for your reply.:slight_smile: