#New to DOTS - trying to get a simple spawning system to work, but entites don't seem to be affected

1 messages · Page 1 of 1 (latest)

foggy grotto
#

I'm trying to get a simple system to work, and I can see the correct number of entities in system view, but the entities aren't being affected

[BurstCompile]
public partial struct EntitySpawnSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state){}
    
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        float dTime = SystemAPI.Time.DeltaTime;
        var ecbSingleton = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
        new EntitySpawnJob
        {
            ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter(),
            deltaTime = dTime 
        }.ScheduleParallel();
        
    }

    [BurstCompile]
    public void OnDestroy(ref SystemState state){}
}

[BurstCompile]
public partial struct EntitySpawnJob : IJobEntity
{
    public float deltaTime;
    public EntityCommandBuffer.ParallelWriter ecb;

    [BurstCompile]
    void Execute(EntitySpawnerData entitySpawner, [EntityIndexInChunk]int sortKey)
    {
        entitySpawner.timeLeft -= deltaTime;
        if (entitySpawner.timeLeft < 0)
        {
            entitySpawner.timeLeft = entitySpawner.spawnDelay;
            var newEntity = ecb.Instantiate(sortKey, entitySpawner.toSpawn);
            
        }
    }
}

Anyone have any idea what am I doing wrong? I thought I'm doing everything correctly.
I'm pretty new to DOTS overall, I'm probably missing something obvious

Funnily enough, if I manually reduce timeLeft on the entities to below zero, the .toSpawn entities are instantiated correctly. So the issue is in the entitySpawner.timeLeft assignment