Grouping multiple arrays in inspector?

I have a spawn script which consists of 3 arrays, an array of gameobjects to spawn, an array of ints for the spawn amount and an array of bools for enable/disable of each object.

Right now it’s messy, I need to look down the list for the corresponding element number:

So I’m wondering if I can group these together so it looks like this:

Any help would be appreciated as I’m new to editor design.

Create a class with these variables, make an array of this class. Decorate class with [System.Serializable]

2 Likes

Wow, thanks that’s working. Is there a way to change the ‘Element 0’ to the name of the prefab I’ll be spawning?

Yes. You’ll need to make a custom property drawer for your serializeable class. The doc example shows exactly your case - an array that gets drawn in a readable way.

EDIT:

You could also consider building a reorderable list, which is what it says on the tin, but also allows you to specify exactly how you draw the elements. There’s a good example here.

Note that you can use EditorGUI.PropertyField to have a property drawn using it’s property drawer - so you can create a reorderable list and have the elements in it drawn using your custom property drawers.

1 Like

Thanks, I’ll take a look at those links.

Yeah the reorderableList takes a little work to setup but lets you draw the data into the list pretty much anyway you want

This is almost what you’re looking for, but if the class has a field ‘name’, that will show up instead of the element number.

3 Likes