Check Max and Min Value

Hello, I am arraying entities in 2d grid layout. I have to find the Max Column and Min Column values so that I can find the maximum distance that the grid can travel left and right on the screen. But the code below is trying to find the max and min values, but the min and max values do not change even if all the columns are gone from the beginning or the end. I guess even though the entities are lost, the component data continues to live in the chunk. Is there a way to delete it completely or to check if a certain component data has an entity?

public partial class AlienMovement : SystemBase
{
    public float time;
    public int index;
    public int maxRowValue;
    public int maxColumnValue;
    public int minColumnValue;
    public bool forward;


    protected override void OnCreate()
    {
        time = 1;
    }
    protected override void OnUpdate()
    {
        var soldierQuery = GetEntityQuery(typeof(Translation), ComponentType.ReadOnly<RowData>(), ComponentType.ReadOnly<ColumnData>());

        Entities
            .WithAll<SpaceInvaderTag>()
            .ForEach((in RowData rowData) =>
            {
                int thisNum = rowData.Row;
                if (thisNum > maxRowValue) { maxRowValue = thisNum; }

            }).WithoutBurst().Run();

        Entities
            .WithAll<SpaceInvaderTag>()
            .ForEach((in ColumnData columnData) =>
            {
                int minNumber = columnData.Column;
                int maxNumber = columnData.Column;
                if(minNumber < minColumnValue) { minColumnValue = minNumber; }
                if(maxNumber > maxColumnValue) { maxColumnValue = maxNumber; }
            }).WithoutBurst().Run();

        Debug.Log("minColumData: " + minColumnValue);
        Debug.Log("maxColumnData: " + maxColumnValue);


        //Zaman 1 sn'ye artıkça index'de 1 artıyor.
        time -= Time.DeltaTime;
        if (time < 0)
        {
            index++;
            time = 1;
        }
        //Row index'i maxValue ulaşınca sıfırlıyor
        if (index >= maxRowValue + 1) { index = 0; }





        //var denemeJob = new DenemeJob
        //{
        //    TranslationTypeHandle = GetComponentTypeHandle<Translation>(false),
        //    RowTypeHandle = GetComponentTypeHandle<RowData>(true),
        //    DeltaTime = Time.DeltaTime,
        //    Row = index
        //};



        //Dependency = denemeJob.Schedule(soldierQuery, Dependency);
        //RequireForUpdate(soldierQuery);


    }
}

public partial struct DenemeJob : IJobEntityBatch
{
    public ComponentTypeHandle<Translation> TranslationTypeHandle;
    [ReadOnly] public ComponentTypeHandle<RowData> RowTypeHandle;
    public float DeltaTime;
    public int Row;

    public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
    {
        var translationArray = batchInChunk.GetNativeArray(TranslationTypeHandle);
        var rowDataArray = batchInChunk.GetNativeArray(RowTypeHandle);


        for (int j = 0; j < batchInChunk.Count; j++)
        {

            if (Row == rowDataArray[j].Row)
            {
                var translation = translationArray[j];
                translation.Value.x += 0.7f * DeltaTime;
                translationArray[j] = translation;
            }

        }

    }

}

Thank you for your concern.

If somebody is interested, here is working script :

public partial class SpaceInvaderMovement : SystemBase
{
    public float time;
    public int index;
    public int maxRowValue;



    protected override void OnCreate()
    {
        time = 1;
    }
    protected override void OnUpdate()
    {
        var soldierQuery = GetEntityQuery(typeof(Translation), ComponentType.ReadOnly<RowData>(), ComponentType.ReadOnly<ColumnData>());

        NativeArray<int> columns = new NativeArray<int>(2, Allocator.TempJob);

        DenemeJob2 denemeJob2 = new DenemeJob2
        {
            columnDataTypeHandle = GetComponentTypeHandle<ColumnData>(true),
            minMaxColumns = columns
        };

        Dependency = denemeJob2.Schedule(soldierQuery, Dependency);
        Dependency.Complete();

        Debug.Log("min column: " + denemeJob2.minMaxColumns[0]);
        Debug.Log("max column: " + denemeJob2.minMaxColumns[1]);



        //Zaman 1 sn'ye artıkça index'de 1 artıyor.
        time -= Time.DeltaTime;
        if (time < 0)
        {
            index++;
            time = 1;
        }
        //Row index'i maxValue ulaşınca sıfırlıyor
        if (index >= maxRowValue + 1) { index = 0; }





        var denemeJob = new DenemeJob
        {
            TranslationTypeHandle = GetComponentTypeHandle<Translation>(false),
            RowTypeHandle = GetComponentTypeHandle<RowData>(true),
            DeltaTime = Time.DeltaTime,
            Row = index
        };



        Dependency = denemeJob.Schedule(soldierQuery, Dependency);
        RequireForUpdate(soldierQuery);

        columns.Dispose();

    }
}

public partial struct DenemeJob : IJobEntityBatch
{
    public ComponentTypeHandle<Translation> TranslationTypeHandle;
    [ReadOnly] public ComponentTypeHandle<RowData> RowTypeHandle;
    public float DeltaTime;
    public int Row;

    public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
    {
        var translationArray = batchInChunk.GetNativeArray(TranslationTypeHandle);
        var rowDataArray = batchInChunk.GetNativeArray(RowTypeHandle);


        for (int j = 0; j < batchInChunk.Count; j++)
        {

            if (Row == rowDataArray[j].Row)
            {
                var translation = translationArray[j];
                translation.Value.x += 0.7f * DeltaTime;
                translationArray[j] = translation;
            }

        }

    }

}

public partial struct DenemeJob2 : IJobEntityBatch
{
    [ReadOnly] public ComponentTypeHandle<ColumnData> columnDataTypeHandle;
    public NativeArray<int> minMaxColumns;

    public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
    {
        var ColumnArray = batchInChunk.GetNativeArray(columnDataTypeHandle);

        if(ColumnArray.Length == 0) { return; }


        int min = int.MaxValue;
        foreach(var column in ColumnArray)
        {
            if(column.Column < min)
            {
                min = column.Column;
            }
        }
        minMaxColumns[0] = min;


        int max = int.MinValue;
        foreach(var column in ColumnArray)
        {
            if(column.Column > max)
            {
                max = column.Column;
            }
        }
        minMaxColumns[1] = max;
    }
}