I have no particular use for now. I can just use the non async version but I just wanted to try it. It’s confusing because it accepts 2 JobHandles:
public NativeList<T> ToComponentDataListAsync<T>(AllocatorManager.AllocatorHandle allocator, JobHandle additionalInputDep, out JobHandle outJobHandle)
I tried doing it this way in a SystemBase:
JobHandle handle = this.Dependency; // So it can be used as an out parameter
NativeList<Entity> entities = this.requestsQuery.ToEntityListAsync(Allocator.TempJob, handle, out handle);
NativeList<RequestAStarSearch> requests = this.requestsQuery.ToComponentDataListAsync<RequestAStarSearch>(Allocator.TempJob, handle, out handle);
// Schedule job using these lists and more stuff
// Assign back
this.Dependency = handle;
However, I’m getting this error:
The system Game.AStarSearchSystem reads Game.RequestAStarSearch via GatherComponentDataJob but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.
Out parameter from the methods should be combined manually with the Dependency from the system.
Otherwise you’re just overriding it with out job handle. (out is not ref keyword)
As for the actual usage - personally I prefer to use only async entities version, because if you’re using ToComponentDataList - you’d probably want to either:
- Iterate on the actual query;
- Or run CDFE lookup and access multiple components simultaneously;
- Or just one component is not enough in general.
Entities list is quite versatile on its own + CDFE / ComponentLookup.
Component version is probably okay-ish if there’s one and only one component you need from the entity as readonly and that won’t change ever.
Or if you want some extra optimizations on top to get rid of random access, which should be profiled fist.
I use ToComponentDataList() for cases where ScheduleGranularity.Entities was used. ScheduleGranularity has been removed. To simulate the same thing, I use ToComponentDataList() instead and use IJobFor for the job.
1 Like
I tried this:
NativeList<Entity> entities = this.requestsQuery.ToEntityListAsync(Allocator.TempJob, this.Dependency, out JobHandle entitiesHandle);
this.Dependency = JobHandle.CombineDependencies(this.Dependency, entitiesHandle);
NativeList<RequestAStarSearch> requests = this.requestsQuery.ToComponentDataListAsync<RequestAStarSearch>(Allocator.TempJob, this.Dependency, out JobHandle requestsHandle);
this.Dependency = JobHandle.CombineDependencies(this.Dependency, requestsHandle);
Same error.
I got it now. The problem was that I was accessing requests.Length when scheduling the job when this is not yet resolved. I used CalculateEntityCount() instead:
NativeList<Entity> entities = this.requestsQuery.ToEntityListAsync(Allocator.TempJob, this.Dependency, out JobHandle entitiesHandle);
this.Dependency = JobHandle.CombineDependencies(this.Dependency, entitiesHandle);
NativeList<RequestAStarSearch> requests = this.requestsQuery.ToComponentDataListAsync<RequestAStarSearch>(Allocator.TempJob, this.Dependency, out JobHandle requestsHandle);
this.Dependency = JobHandle.CombineDependencies(this.Dependency, requestsHandle);
// On schedule, do not use requests.Length here
this.Dependency = searchJob.Schedule(this.requestsQuery.CalculateEntityCount(), 5, this.Dependency);
1 Like