Using a Component array in the editor

Hi.
I tried to create a small script, which destroys different Components of different GameObjects when triggered. So the simplest idea was a Component array like this:

public Component[] destroyOnTrigger;

public void trigger()
{
    foreach(Component c in destroyOnTrigger)
        Destroy(c);
}

But when trying to drag and drop Components into that array in the editor, it seems impossible first. This is simply because the inspector view does not change from the GO where the Component is attached, to the GO with the Component array.


Using the select button won’t help either, since you only get Transform Components (and filtering for t: does not work).

I almost gave up, when I noticed this:
1. You can open another Inspector (right click Inspector > Add Tab > Inspector). Drag the second one somewhere into your UI, so you can see both at once. They will both show the same things, but you can lock the view.

2. So select the GO with the Component array and lock one Inspector (right click Inspector > Lock).

3. Now select the GO with the desired Component. You can drag and drop Components from one Inspector to the other.

I don’t know if this behaviour is intended and everybody except me knew about it, but I could only find one very old thread about it (Component Array as variable? - Unity Engine - Unity Discussions). So, I hope I could save somebody some time finding this out.
I posted into “GUI”, because it felt like a GUI issue to me and it could be further discussed here.

Have a nice day ^^
Cheers

This is indeed a working solution. You could also make an editor script that allows you to pick a component from the gameobject you dropped on if you don’t want to clutter your unity layout with inspectors :stuck_out_tongue: