Unity3D tip: edit arrays of custom objects in object inspector

05 May 2013
Say I have the following component:
public class Test: MonoBehaviour
{
    public Vector3[] PivotPoints;
}
It’s OK to edit the PivotPoints field in object inspector, because Unity natively understands Vector3 struct and displays it properly. Things get more complicated when I add field representing an array of custom objects:
class NodeSetup
{
    public Vector3 Position;
    public Vector3 Weight;
}

// ...

public class Test: MonoBehaviour
{
    public Vector3[] PivotPoints;
    public NodeSetup[] NodeSetups;
}
Unity ignores field NodeSetups. First I thought I should write a custom editor in order to edit such fields. Fortunately the problem has simple solution – just mark your custom class with Serializable attribute:
[Serializable]
class NodeSetup
{ ... }
© 2014-2017 Aleksey Fedotov