#ECB with TempJob allocation lasting more than four frames

1 messages · Page 1 of 1 (latest)

summer smelt
#

I am trying to parallelise my instantiation code, I switched to a new ecb to use as a parallel writer and I assigned it the TempJob allocation however it is still lasting more than four frames. Do I need to manually deallocate it?
Here is the job and the code calling it:

private void Spawn(ref SystemState state, int amount)
    {
        EntityCommandBuffer ecb = 
                new EntityCommandBuffer(Allocator.TempJob).AsParallelWriter();

        new SpawnEnemyJob { ECB = ecb, Amount = amount }.ScheduleParallel();
    }

[BurstCompile] public partial struct SpawnEnemyJob : IJobEntity
{
    public EntityCommandBuffer.ParallelWriter ECB;
    public int Amount;    

    private void Execute([ChunkIndexInQuery] int ChunkIndex, GameAspect game)
    {
        for (int i = 0; i < Amount; i++)
        {
            var newEnemy = ECB.Instantiate(ChunkIndex, game.EnemyPrefab);

            ECB.SetComponent(ChunkIndex, newEnemy, new LocalTransform
            {
                Position = game.EnemySpawn(),
                Rotation = UnityEngine.Quaternion.identity,
                Scale = 1 + game.RandomFloat(0.2f)
            });
        }        
    }
}

Should I just use Allocater.Persistent then deallocate it later myself?

wary cedar
#

you aren't doing anything with your ECB

#

you're allocating and never playing back