Custom inspector, a multidimensional array of enums


I’ve been searching everywhere for a solution, but cannot find it. I want to set parameters of some array as prefabs, and decided to use a custom inspector to edit these prefabs (rather than hard coding each individual class object.

Here’s what I have:

using UnityEngine;
using System.Collections;

public class Something : MonoBehaviour {
	public enum MovementTypes { None, Move, Jump};
	public MovementTypes[,] Movement = new MovementTypes[5,5];
	public string Name;

And my Editor/ has

using UnityEngine;
using System.Collections;
using UnityEditor;

public class SomethingEditor : Editor {
	public override void OnInspectorGUI()
		Something myS = (Something)target;

		myS.Name = EditorGUILayout.TextField("Type Name", myS.Name);

		for (int y = 0; y < 5; y++)
			EditorGUILayout.BeginHorizontal ();
			for (int x = 0; x < 5; x++)
				myS.Movement[x, y] = (Something.MovementTypes)EditorGUILayout.EnumPopup(myS.Movement[x, y]);
			EditorGUILayout.EndHorizontal ();


This code graces me with the following errors:

  • NullReferenceException: Object reference not set to an instance of an object
    SomethingEditor.OnInspectorGUI () (at Assets/Editor/SomethingEditor.cs:17)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1124)
  • Unexpected top level layout group! Missing GUILayout.EndScrollView/EndVertical/EndHorizontal?

I’ve tried a bunch of things, and nothing works. I cannot edit the 5x5 array. The only work around I can fathom right now is to make 25 separate variables…

I cannot help with custom editor, but you can setup array of arrays (two dimensional array) of enums in the inspector in the following way.

	public class class1{
		public enum myEnum {one,two,three};
		public myEnum[] row;
	public class1[] array;

In the inspector you get this :