#Having trouble creating generic IJobChunk

1 messages · Page 1 of 1 (latest)

coarse dragon
#

Hi, I'm having some trouble in Entities 1.0.0-pre.15.

I want to create a generic job for dealing with components that have a limited lifetime. I've learned that IJobEntity's code generation does not support generic jobs, but it should theoretically be possible to write my own IJobChunk. However, I'm getting a persistent error that I have not been able to solve.

A minimal version of the job code in question is

using Unity.Entities;
using Unity.Burst;
using Unity.Burst.Intrinsics;
using Unity.Collections;

[BurstCompile]
public partial struct StatusCountdownJob<T> : IJobChunk
    where T : struct, IComponentData, IStatus
{
    ComponentTypeHandle<T> StatusHandle;

    public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) {
        NativeArray<T> statuses = chunk.GetNativeArray<T>(ref StatusHandle);

        for (int i = 0; i < chunk.Count; ++i)
        {   
            // do stuff
        }
    }
}

IStatus is:

using Unity.Entities;

public interface IStatus : IComponentData
{
    public float TimeRemaining { get; set; }
}

however removing it from the generic type does not fix the error.

The resulting error is:

Assets/Scripts/GenericJobs/StatusCountdownJob.cs(21,41): error CS8377: The type 'T' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'ArchetypeChunk.GetNativeArray<T>(ref ComponentTypeHandle<T>)'
I believe that declaring that T must be a struct should already make it a non-nullable value type, so I'm not sure why I'm getting this error.

Please could I ask for some advice solving this?

swift wagon
coarse dragon
#

amazing, that cleared it, thank you so much!

coarse dragon
#

Unfortunately I'm still having trouble. I have it compiling, but trying to get an entity with

NativeArray<Entity> entities = chunk.GetNativeArray(EntityHandle);

and then accessing the array with entities[i] is throwing an out of bounds error. Getting an array of components does not throw this error. I'm very confused, everything I can find seems to suggest this is the correct way to access an entity. Please could I ask for help again?

coarse dragon
#

On further investigation the problem is not accessing this array, but that after the component has been removed, the job continues to run on an empty chunk, and yet the count returns 1, not 0. I think maybe the SystemAPI codegen isn't updating the entityqueries?

scenic wedge
#

How are you scheduling your job? - also codegen doesn't deal with updating queries. Even in normal user code, you don't update queries cause they selfmaintain

coarse dragon
#

argh, I found the bug, I'm sorry >< it was a copy-paste error.

#

I passed the wrong ComponentTypeHandle to a job

#

thank you for taking a look Dani