Array in IComponentData struct

I read this.

I try to add array of way points float3[ ] wayPoints to unsafe struct WayPoints: IComponentData which of course, didn’t work.
So in future of C# 7.3, would it possible to add buffer of array to struct?
Or keeping fixed array inside unsafe struct is generally bad idea?

Edit: there is buffer array which can be use as array in struct

Looks like you’re not using the ‘fixed’ keyword. Try:

fixed float[3] waypoints;

Unfortunately fixed arrays only work with blittable, basic types (byte, int, float, etc). So a fixed array of float3 won’t be supported. Neither will a nested fixed array.

Would there be any down size if I have a struct too large for many entities?. I know there is a limit of how much chunk memory can be loaded to CPU.

You just named the main downside. The larger your structs, the fewer of them will be able to fit in a Chunk. All that will mean is that you’ll have more cache misses while iterating over chunks, since Unity will need to jump around in ram more often.

…I’m not sure if 16kb is a hard limit for Component size, but ideally a component shouldn’t be anywhere near that. :slight_smile:

1 Like

“Oversized” Buffer Arrays for example, are stored on the heap, rather than in chunks. So there is no issue with a size.

1 Like