Make Job/Entities available everywhere.

Sometimes I just want to call Entities.ForEach somewhere in my non ECS code

This thing clearly didn’t work:

NativeArray<Entity> ent = new NativeArray<Entity>(1, Allocator.TempJob);
ent[0] = default;
int entc = EntityCode;
default(ForEachLambdaJobDescriptionJCS).ForEach((in Entity e, in RuntimeEntityIdentifier id) => {
    if (entc == id.Value) {
        ent[0] = e;
    }
}).Schedule(default).Complete();
ent.Dispose();

You can create a system instead but use another method to do the ForEach() instead of in OnUpdate(). Then you can cache that system using World.GetOrCreateSystem() then call the method that you created.

Or there could be a new feature, in the next version, that let you call some static class that works just like Entities and Job that skips this awkward workaround.

Up to you, man. Use the workaround or wait for your requested feature that might never be implemented.

I don’t think this is planned to be implemented as all that Entities.ForEach does is to generate a bunch of code, which some are very specific to SystemBase (like WithStoreEntityQueryInField). So yes, the workaround here is to create a dummy system to do that for you or (my personal choice) use IJobChunk instead.

2 Likes