Issue with ECS and blittable types

Stated in MS doc, One-dimensional arrays of blittable types(like int[ ]) is blittable type, where Unity throws an error:

ArgumentException: DungeonQuest.Componants.HotBarComponant is an IComponentData, and thus must be blittable (No managed object is allowed on the struct)

when I using int[ ].
Here is my code that follow MS guide about blittable.

public struct HotBarComponant: IComponentData
    {
public int[] items
    }

Is there some Unity doc about what type of data types they support since they dont seem to support the types that MS state are blittable.

nvm struct and class that contain arrays of blittable is not blittable itself…why…lol

You may be interested in FixedArray instead.

2 Likes

For a IComponentData to be blittable it has to be a fixed size and be layed out linearly in memory. int[ ] itself is blittable but having a struct with a reference to it is not. Size is variable and actual content is stored somewhere else on the heap.

Or saying it differently: if it is a blittable type by Microsoft’s definition and it is a value type it should work.

The website you mentioned actually says so too:

The following complex types are also blittable types:

  • One-dimensional arrays of blittable types, such as an array of integers. However, a type that contains a variable array of blittable types is not itself blittable.