Unable to serialize uint array

[SerializeField]
[HideInInspector]
internal int a = new int[40];

 	[SerializeField]
	[HideInInspector]
	internal uint [] b = new uint[40];

The int array serializes, but the uint version doesn’t. Is this a bug in Unity, or am I doing something wrong?

1 Answer

1

As per the documentation, looks like uint is not supported. Why not just use int? You could make an editor script force it to be positive if that’s your concern.

"

Serializable types are:

  • All classes inheriting from UnityEngine.Object, for example
    GameObject, Component, MonoBehaviour,
    Texture2D, AnimationClip… - All basic
    data types like int, string, float,
    bool. - Some built-in types like
    Vector2, Vector3, Vector4, Quaternion,
    Matrix4x4, Color, Rect, LayerMask… -
    Arrays of a serializable type
  • List of a serializable type (new in Unity2.6)
  • Enums"

Yup, would be great if Unity supported signed and unsigned byte, short, int, and long. (Not to mention allowing enum types to be of all these types too, as permitted by C#.)