Is there any way to create collections of native collections and use them with Burst? For example, NativeArray<NativeArray> won’t compile since NativeArray is not blittable and NativeArray[ ] is a reference type.
Is there support for this at all or should we resort to passing an array of pointers instead?
Look up forum posts here for DynamicBuffer that can have a list elements on entities, or if your looking at a grid shape (IE, 4x4,16x16, etc), you can do your own math to map a 2d index to a 1D grid and back.
Yeah, the thing is, this data is not on entities and I would like to avoid using them here.
Using simple maths to go between 2 and 1 dimensional indices doesn’t really work all that well once you start using collections different than fixed sized arrays (list of queues, array of lists, etc). It’s also not the most efficient when you need a jagged array
I’ve made a post about creating jagged arrays as it seems the Native collection questions have become popular again:
That being said, it may be possible to pass an NativeArray array of struct-wrapped Pointers to other NativeArrays / containers if you’re willing to ensure they’re stable/ReadOnly and turn of certain safety checks. I don’t know if this will get you the perf gains you’re looking for since burst works best with blocks of linear data.
It may be better manage your lists of structures only on the main thread and schedule individual jobs to deal with each sub-structure if/where processing doesn’t have overlapping access (if you don’t need to write to two containers at the same time).
You could design your own NativeCollections too, look at this guy’s work for nice detailed concrete examples :