#Getting EntityCommandBufferSystem.Singleton

1 messages · Page 1 of 1 (latest)

sturdy zodiac
#

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>();
    }
}
supple mauve
#

the command buffer system creates the singleton in oncreate

#

so if you're system is created before this point it doesn't exist yet

#

generally you just grab it in onupdate

#

if you insist in doing it in oncreate you need to use [CreateAfter(commandbuffersystem)] on all your systems

sturdy zodiac
supple mauve
#

no

#

it only affects create and destroy order

#

update order is dependent on system groups, updateafter etc

#

also there's no need to do a
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();