Hi, I need to create Component that can store some kind of array/list of structs, but IComponentData must be blittable so it’s not possible to do it that way. Can you tell me how should I approach making component that can store array/list?
There are a few ways to achieve this:
- Make more than one entity, and store components on each one of them. You can group them together and rediscover the list via shared component data or manual querying. Entities are cheap to make.
- Use a fixed array component
- Store the data somewhere else and use an offset/count pair in the component data (not recommended)
1 Like
Thnx @deplinenoise I get FixedArrayArray. But just out of curiosity, could you explain what FixedArrayFromEntity is used for?
FixedArrayArray doesn’t seem to work anymore inside IComponentData with the latest preview version. It says it’s not blittable anymore. Any hints?
You can not add a FixedArray directly to a component as field.
Just add it like that to an enitity
em.AddComponent(entity, ComponentType.FixedArray(typeof(int), size));
5 Likes
I think Monobehaviour is the best to store list at the moment.