Recently I transferred my project from Entities 0.51 to 1.0.
I’m trying to create a cellular automata kind of game like Powder Toy. The game’s world is separated in Chunks of pixels like this (I apologize for the horrible magenta colour, it’s for debugging reasons):
So, there is a WorldGenerationSystem that I am using to generate the world’s terrain by filling Chunks’ DynamicBuffers with pixels (which are entities). Right now I’m trying to use an IJobEntity struct for this system which I haven’t been using previously – it worked just fine like that until 1.0, then I got 8 FPS even thought there was nothing being processed at all.
At this stage of development, the system’s logic runs only once in the OnStartRunning method for testing purposes.
Here’s the simplified version of the code:
protected override void OnStartRunning()
{
base.OnStartRunning();
EntityCommandBuffer commandBuffer = GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>().CreateCommandBuffer(World.Unmanaged);
new GenerateRegionJob()
{
pixelBuffers = GetBufferLookup<PixelBufferElement>(),
commandBuffer = commandBuffer
}.Schedule(regionQuery, Dependency).Complete();
endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
}
I followed the Turbo Makes Games tutorial on this.
GenerateRegionJob’s purpose is to create pixels using the passed commandBuffer.
I guess that would be working fine, if I haven’t been assigning the newly created pixels to the pixelBuffers of the Chunks I create the pixels for, like in this GenerateRegionJob piece of code:
private void CreatePixel(Entity chunk, int index)
{
Entity newPixel = commandBuffer.CreateEntity(pixelArchetype);
commandBuffer.SetComponent(newPixel, /*some creation data*/);
pixelBuffers[chunk][index] = newPixel;
}
So, the problem is, when I try to access the entities I created inside of the job by indexing DynamicBuffers, Unity tells me that they’re still deferred. I assume that’s because those buffers store a copy of the deferred pixel entities (with negative entity indexes) and that doesn’t change when the playback is called.
Storing tose pixels in DynamicBuffers (or any ordered containers) is obviously vital for my game and I cannot treat them individually.
Could anyone please provide me with any suggestions on finding a workaround for that?