I am having issues with getting the EntityCommandBufferSystem.Singleton's that unity creates from the create function of my own systems. It works with some systems and other times I get an error say the specific component, in my case specifically EndSimulationEntityCommandBufferSystem.Singleton, does not exist.
Is this due to my system being created before the EndSimulationEntityCommandBufferSystem? If so can I solve this somehow or should I just get the buffer system each time in the update function?
Example of the particular system that is not working for me.
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct MySystem : ISystem
{
private EntityQuery _query;
private EndSimulationEntityCommandBufferSystem.Singleton _ecbs;
[BurstCompile]
public void OnCreate(ref SystemState state)
{
_query = new EntityQueryBuilder(Allocator.Persistent)
.WithAll<RegularComponent, SharedComponent>()
.Build(ref state);
state.RequireForUpdate(_query);
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
_ecbs = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
}
}