#how to write back changes from a job

1 messages · Page 1 of 1 (latest)

jagged stream
#
using Unity.Burst;
using static UnityEngine.EventSystems.EventTrigger;

[UpdateInGroup(typeof(LateSimulationSystemGroup))]
[UpdateAfter(typeof(HealthSystem))]
public partial struct PendingKillSystem : ISystem
{
    Entity counterEntity;
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<PendingKillComponent>();
        counterEntity = SystemAPI.GetSingletonEntity<EnemyCounterComponent>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        EnemyCounterComponent counter = state.EntityManager.GetComponentData<EnemyCounterComponent>(counterEntity);


        PendingKillJob killJob = new PendingKillJob
        {
            ecb = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>()
                            .CreateCommandBuffer(state.WorldUnmanaged)
                            .AsParallelWriter(),
            localCounter = counter
        };
        killJob.ScheduleParallel();
    }

    [BurstCompile]
    private partial struct PendingKillJob : IJobEntity
    {
        public EntityCommandBuffer.ParallelWriter ecb;
        public EnemyCounterComponent localCounter;

        [BurstCompile]
        public void Execute([ChunkIndexInQuery] int index, Entity e, in PendingKillComponent killComp)
        {
            ecb.DestroyEntity(index, e);
            localCounter.ActiveEnemyCount--;
        }
    }
}```

im trying to update my enemy counter components variable from my kill system however because im creating a copy of the variable it doesn't update