IComponentData not blittable

I’m getting weird error message:

ArgumentException: Components.EntitySpawnerData is an IComponentData, and thus must be blittable (No managed object is allowed on the struct).
Unity.Entities.TypeManager.BuildComponentType (System.Type type) (at Library/PackageCache/com.unity.entities@0.0.12-preview.23/Unity.Entities/Types/TypeManager.cs:499)

This is how component data is defined:

[Serializable]
    public struct EntitySpawnerData : IComponentData {
        public bool SpawnOnTap;
        public bool SingleEntity;
        public bool HasEntityAttached;
        public float EntitySpawnDelay;
        public float LastSpawnTime;
    }

What am I missing? Do I need to use StructLayout + Explicit because data has 11 bytes?

I think that “bool” type is not supported currently.

1 Like

Right, just found out from here about that:
https://gametorrahod.com/unity-ecs-know-your-blittable-types-360b8f9a7f4a

Jeez that is not obvious.

@Kichang-Kim linked my post, here is the solution of that and a PropertyDrawer for the inspector! Have fun :wink:

using System;
using UnityEngine;

[Serializable]
public struct boolean {
    [SerializeField] private byte boolValue;

    public boolean(bool value) {
        boolValue = (byte)(value ? 1 : 0);
    }
    public static implicit operator bool(boolean value) {
        return value.boolValue == 1;
    }
    public static implicit operator boolean(bool value) {
        return new boolean(value);
    }

    public override string ToString() {
        return ((bool)this).ToString();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[CustomPropertyDrawer(typeof(boolean))]
public class booleanPropertyDrawercs : PropertyDrawer {

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
        var booleanProp = property.FindPropertyRelative("boolValue");
        booleanProp.boolValue = EditorGUI.Toggle(position, label, booleanProp.boolValue);
    }
}
1 Like

Lol, I’ve just made the same thing:

I saw a sample somewhere from unity about that

Do it this way:
[Serializable]
public struct EntitySpawnerData : IComponentData {
public Carrier Value;
}

[Serializable]
public struct Carrier
{
public bool SpawnOnTap;
public bool SingleEntity;
public bool HasEntityAttached;
public float EntitySpawnDelay;
public float LastSpawnTime
}

If you can adjust your logics, you could also do:

public bool3 boolValues;
public float2 floatValues;

1 Like