Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Drag multiple items into inspector

Discussion in 'Editor & General Support' started by BeforeTheLight, Jan 6, 2013.

  1. BeforeTheLight

    BeforeTheLight

    Joined:
    Jan 7, 2011
    Posts:
    163
    I know this is probably stupid but is there a way to drag multiple objects into a array in the inspector? Thank you.
     
  2. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    394
    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.
     
  3. BeforeTheLight

    BeforeTheLight

    Joined:
    Jan 7, 2011
    Posts:
    163
    I have never noticed that lock up there. Thank you very much!
     
  4. StartStart

    StartStart

    Joined:
    Jan 2, 2013
    Posts:
    141
    Whoa it's work like charm. Thank you so much.
     
  5. skrpeta

    skrpeta

    Joined:
    Nov 9, 2016
    Posts:
    18
    Literary tear went from my eye when I successfully done this! Thank you RazorCut
     
    Thaina and aloften like this.
  6. paruthi-exe

    paruthi-exe

    Joined:
    Mar 11, 2015
    Posts:
    12
    OMG thanks @RazorCut for this.. helped a lot.. thinking of writing a editor tool for this..
     
  7. rallyall

    rallyall

    Joined:
    Dec 20, 2019
    Posts:
    36
    okay but how do you select multiple child objects (say text) and drag them all at once into the inspector to populate an array?
     
  8. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    507
    @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:
    1. If it's a GameObject or UnityEngine.Object array, it adds the dragged GameObjects to the array.
    2. If it's a Component or Transform array, it adds the Transform component from each dragged GameObject to the array.
    3. 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:
    1. Select the target containing the array.
    2. Lock the inspector.
    3. Open another inspector by selecting "Add Tab/Inspector" from the context menu of any other editor window.
    4. Select a GameObject containing one of the components you want to add to the array.
    5. Drag and drop the component from the second inspector to the array in the locked inspector.
    6. Repeat steps 4 to 6 until all components have been added to the array.

    I hope this answers your question :)
     
    tatanneitor likes this.
  9. rallyall

    rallyall

    Joined:
    Dec 20, 2019
    Posts:
    36
    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.
     
  10. MikoGot

    MikoGot

    Joined:
    May 31, 2018
    Posts:
    1
    Does it also work for Scriptable Object type items? I tried but only first from selected is assigned ;(
     
  11. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    154
    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.
    Code (CSharp):
    1. public class FlipBookPlayer
    2. {
    3.    public Frame[] frames;
    4. }
    5. [Serializable]
    6. public struct Frame
    7. {
    8.    public Sprite sprite;
    9.    public float duration;
    10. }
     
unityunity