x


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.

more ▼

asked Oct 31, 2010 at 03:49 PM

ExciteMike gravatar image

ExciteMike
103 7 6 12

i never understood why they didn't replicate the Script Execution Order editor for arrays in the inspector. DragDrop reordering thanks!

Jan 15, 2013 at 12:37 PM duke
(comments are locked)
10|3000 characters needed characters left

6 answers: sort voted first

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.

more ▼

answered Oct 31, 2010 at 04:33 PM

Jesse Anders gravatar image

Jesse Anders
7.7k 11 25 61

My suggestion is to request it. http://feedback.unity3d.com/

Oct 31, 2010 at 05:31 PM Jessy

List seemed to do the same thing as an array, but it turned out it wasn't a big deal to write a custom editor for this one case. It came out looking like this: http://www.pasteit4me.com/1473001

I don't suppose it's possible to do make Unity use a custom editor on all arrays all over the place, is it?

Oct 31, 2010 at 08:35 PM ExciteMike

Hey Jesse Anders, I know this post is quite old, but I've been trying to do this exact thing for days now and can't figure it out. Your solution is exactly what I've been trying to do. You mention you've done it with the buttons for up and down before. How did you get which item is selected? or how did you display the array contents for that matter?

Jan 31, 2012 at 10:26 PM Adsy

@ExciteMike do you still have that code?

Nov 13, 2012 at 02:49 PM sebas77

I'm pretty sure I still have it... but I can't remember which project I was working on at the time, which makes it really hard to find :/

Nov 13, 2012 at 03:49 PM ExciteMike
(comments are locked)
10|3000 characters needed characters left

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:

alt text

screenshot.png (13.3 kB)
more ▼

answered Oct 03, 2013 at 11:50 PM

numberkruncher gravatar image

numberkruncher
4.3k 139 97 122

Very cool! I'd vote that up, but I have no reputation. :\

Oct 04, 2013 at 01:02 AM Michael Ryan

I use that one too. Best solution I've found. Need to create a custom inspector, but it's worth that small effort.

Mar 08 at 11:42 AM Tortuap

great stuff :-)

Mar 25 at 02:34 AM Julian Glenn
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Dec 18, 2011 at 09:43 PM

Zogg gravatar image

Zogg
121 6 4 7

Does Ctrl-Delete work on Windows?

Dec 18, 2011 at 10:27 PM Michael Ryan

Use Shift-Delete to delete on Windows (Using 3.5 beta).

Jan 14, 2012 at 04:40 PM centaurianmudpig

On windows, you can simply press the 'Delete' key instead of Ctrl-Backspace :)

Aug 15, 2013 at 02:23 PM KainAsylum
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 31, 2010 at 05:16 PM

Eric5h5 gravatar image

Eric5h5
107k 52 180 648

Depends how simple the "value" is. I have arrays of big complicated structs, and they're nested (so CustomEditor can't really help). Time to write the array reordering window suggested above.

Jun 02, 2011 at 01:09 AM Waz

Ugh. Done, but it's so ugly, and SerializedProperty is so under-documented and full of gotchas, that I'm not going to post it anywhere.

Jun 02, 2011 at 02:22 AM Waz
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Dec 09, 2011 at 04:32 PM

Michael Ryan gravatar image

Michael Ryan
78 3 4 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5491
x2060
x750

asked: Oct 31, 2010 at 03:49 PM

Seen: 8078 times

Last Updated: Mar 25 at 02:34 AM