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?
@Kichang-Kim linked my post, here is the solution of that and a PropertyDrawer for the inspector! Have fun
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);
}
}
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
}