Toggles in Inspector Not Working Properly

I’m working on a simple editor extension for a class project, but I’ve run into a bit of trouble; namely, I’ve set up a grid of Toggle inputs to allow editing of a 2D array of Boolean values (a mask for a Diablo-style inventory). However, they don’t seem to detect when they are or aren’t getting clicked on. I’ve set it up like so:

    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();
        EditorGUILayout.BeginVertical();

        for (int y = 0; y < Target.MaskHeight; y++)
        {
            EditorGUILayout.BeginHorizontal();
            for (int x = 0; x < Target.MaskWidth; x++)
            {
                Target.Mask[x,y] = EditorGUILayout.Toggle(Target.Mask[x, y], GUILayout.Width(16));
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();
    }

Occasionally, clicking on one will toggle it, but most of the time nothing happens. It seems to be something to do with where the “hitbox” for the Toggles are. Any ideas would be very welcome - I’ve been staring at it for some time now, but it’s getting late and I’m not making much progress. Thank you for your time,

Timothy Sassone

[EDIT]: Upon some further testing, it seems they do all work, but the “hitbox” I have to click in to change them is tiny - the top-left 2x2 pixel box or so. Ideas?

I’m not aware of any way to change the size of the toggle box itself, it seems to be pretty set in stone unless I’ve missed something. Some people over here in the forums were talking about using styles, but I’m no good at that.

Were I you, I’d just use a button instead, since those can be resized. It’s a little more code, but works out to what you want I’d say. Without testing, I’d say make your own little function something like this:

public bool CustomToggle(bool myToggle, int height, int width) {
	string boxChecked;
	
	if (myToggle) {
		boxChecked = "X";
	} else {
		boxChecked = "";
	}
	
	if (GUILayout.Button(boxChecked, GUILayout.Height(height),
		GUILayout.Width(width))) {
		
		myToggle = !myToggle;
	}
	
	return myToggle;
}

from there you could easily just call similar to what you had:

public override void OnInspectorGUI()
{
    EditorGUIUtility.LookLikeInspector();
    EditorGUILayout.BeginVertical();

    for (int y = 0; y < Target.MaskHeight; y++)
    {
        EditorGUILayout.BeginHorizontal();
        for (int x = 0; x < Target.MaskWidth; x++)
        {
            Target.Mask[x,y] = CustomToggle(Target.Mask[x, y], 16, 16);
        }
        EditorGUILayout.EndHorizontal();
    }

    EditorGUILayout.EndVertical();
}

the only difference in the end would be that you have a button with an X or nothing instead of an actual check box, but now you can space and size it however you like.

Edit: I can’t seem to get the formatting from my code to work no matter how I fix it up - it shows properly in the preview but not in the answer. Here is a pastebin with it looking better: http://pastebin.com/Wj7J8MuD

ye i had this problem restart your cp than leave it alone for a day then try again