how to cache the query object of a forEach

I’m wondering if it is possible to cache the query object of an Entities.ForEach job? I know I can store a reference to the query with WithStoreEntityQueryInField, but this isn’t useful for caching since it appears forEach will still create a new query object at every update. Seems wasteful. Is IJobChunk the way to go if you want to the most optimized job?

It won’t create a new one at every update, it will create once inside OnCreate by codegen

Fantastic. I missed that in the documentation. Thank you very much. Where does it say that it works like that?

Don’t recall if there is anything in the documentation about that, but you can just look into the generated code inside the Editor (DOTS → DOTS Compiler → Open Inspector)

2 Likes

Fantastic, It’s right there in the generated code. Thank you very much.

1 Like