Drag multiple items into inspector

I know this is probably stupid but is there a way to drag multiple objects into a array in the inspector? Thank you.

3 Likes

Yeah. Typically you have to lock the inspector so you can select all the stuff. Then you drag them to the array name in the inspector. Then unlock.

24 Likes

I have never noticed that lock up there. Thank you very much!

1 Like

Whoa it’s work like charm. Thank you so much.

Literary tear went from my eye when I successfully done this! Thank you RazorCut

2 Likes

OMG thanks @RazorCut for this… helped a lot… thinking of writing a editor tool for this…

okay but how do you select multiple child objects (say text) and drag them all at once into the inspector to populate an array?

@rallyall

If you drag multiple GameObjects from the hierarchy window onto an array header, values are added to the array based on the following logic:

  • If it’s a GameObject or UnityEngine.Object array, it adds the dragged GameObjects to the array.
  • If it’s a Component or Transform array, it adds the Transform component from each dragged GameObject to the array.
  • If the array element type is some other Component-derived type, then the first component from each dragged GameObject that matches said type is added to the array.

So in the case of a Text array, you can simply select multiple GameObjects containing a Text component and drag them to array header.

If the array element type is not specific enough (e.g. Component[ ]), you might be out of luck, and just have to drag them to the array one by one. To do this you have to do the following:

  • Select the target containing the array.
  • Lock the inspector.
  • Open another inspector by selecting “Add Tab/Inspector” from the context menu of any other editor window.
  • Select a GameObject containing one of the components you want to add to the array.
  • Drag and drop the component from the second inspector to the array in the locked inspector.
  • Repeat steps 4 to 6 until all components have been added to the array.

I hope this answers your question :slight_smile:

1 Like

Yeah I was missing the tiny detail that you drag to the header- it’s a very tiny target to hit. And not within the array itself.

1 Like

Does it also work for Scriptable Object type items? I tried but only first from selected is assigned ;(

Is there a way to write custom drag handler, which can initialize array (or any other field) of custom type with bunch of dropped assets? In my case i want to be able to drag and drop bunch of sprites to my array of struct which include Sprite field.

public class FlipBookPlayer
{
   public Frame[] frames;
}
[Serializable]
public struct Frame
{
   public Sprite sprite;
   public float duration;
}
2 Likes

I wanna drag folders but can’t.

There should be a way somehow to do it with an editor script by the way, might look into it now…

Thank you RazorCut

RAZOR CUT THANK YOU SO MUCH

This helped me

Hey, did you solve your issue?

No. But there is a way to implement ScriptableObject creation from selection of set of assets. In my case I was just selecting set of sprites and then hit create my SO from context menu, which appeared with initialized Frame structs.

The main idea is to handle current editor asset selection and produce some data depending on it. It can be used with any kind of things not necessarily with SO.

1 Like

Good. I have been searching and found this working drag and drop script editor https://gist.github.com/bzgeb/3800350.

1 Like

An alternative to locking the inspector is to right click on the game object and select “Properties” This will open a second inspector that works exclusively for that game object. Depending on the context I will use either this or lock it or to accomplish populating an array.

1 Like