array inspector reordering

My component has an array property for an ordered list of other GameObjects that it will work with. When I need to change the order of those game objects, it's a bit of a pain. In the worst case, moving the last one to the first slot, I need to reset every single element. Is there some other way of doing it? It'd be slick if I could drag elements around in the list, but that doesn't seem to work.

I have created a custom control which does allow items to be rearranged using drag and drop:

Reorderable List Editor Field for Unity:

https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity

Screenshot:

While there is no easy way to move elements around, you are able to duplicate existing array items and remove elements from the array using some shortcut keys.

From the Unify Community wiki:

Builtin arrays are the only reasonable way to allow artists and level designers to define lists of things without touching code or making your own editor extensions. However, editing long arrays can get tedious if you are relying on things being in a certain order and you need to make changes later.

There are two undocumented functions you can use when editing arrays:

Command-Delete (Ctrl-Backspace on Windows): Remove the selected element in an array. The element will be deleted, the array length will be reduced by one and subsequent elements will each have their indices reduced by one.

Command-D (Ctrl-D on Windows): Duplicate the selected element. The element will be duplicated, with the duplicate inserted after the selected element. The array length will be increased by one, and all subsequent elements will have their indices increased by one.

I have no idea why these functions are undocumented and only available via shortcut, but they can save your day when you realize that element 4 in an array of length 50 shouldn’t be there.

You might try using a List instead. IIRC, the inspector interface for List reflects that its interface is substantially different from that of an array (for example, I believe you can delete items in the list freely without affecting the values of other items). This still won't allow you to drag items around as you describe, but it might be an improvement over what you have currently.

Another option might be to create a custom inspector or editor window that facilitated whatever operations you might need to perform. For example, you could create an editor window where you can select items in the list and then click 'up' or 'down' buttons to move them up or down in the list. (I've used this method myself, and it worked fine.)

Maybe someone else will be able to off a better suggestion though.

Actually, Ctrl-D works on Windows, but Ctrl-Backspace doesn’t.

As far as moving the last one to the first slot, you can duplicate the first slot, change the value of the duplicate, and delete the last slot. You don't need a List for that; it works fine with an array.

The way I approach this issue is by following a rule that all variables in scripts must get initialized with Editor scripts.

If I need to change the order of an array, I change the code that initialized the array and run the editor script again.

Our last project had about 10-20 minutes worth of linking that needed to be done when a new Maya Scene was imported.

Things are going much better in this project, where everything is initialized by a single ScriptableWizard.

You may have a look at: Reorderable Arrays

I’ve found great script with context menu for this task.

Here.