Data indexing strategy when moving to IComponentData?

In pre-ECS I have my data as an array of Vector3 which takes an index of 0~4 to access. But now that I use ECS IComponentData cannot accept arrays or even native containers. For this

  • If I want to keep the rest of my code intact I would have to find a way to index this data. The obvious way is to if or switch case on the indexer and link to each data individually. But I heard you need to stay away from branching in job codes so I use math.select like the documentation says. But it looks very ugly as you can see. Any better way than this?

  • I just put some variables with custom names on it. Is there any way to say “5 float3 here” or something in IComponentData ? If I can do that I might not need all that math.select and maybe have some ways to map integer to the correct data. Fixed length is fine, and that would be still in IComponentData’s design. Kind of like this :

Then throws at runtime if you attempts to use out of bounds memory etc.

  1. You can cast it to a float3* (unsafe) and index that way.
  2. However, you’re virtually guaranteed to be reading data you don’t need with this component design. There’s probably a higher level change that would give you better results if we knew more about the calling context.
1 Like