Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. 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:
    168
    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:
    393
    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:
    168
    I have never noticed that lock up there. Thank you very much!
     
    Jamisco likes this.
  4. StartStart

    StartStart

    Joined:
    Jan 2, 2013
    Posts:
    150
    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:
    1,114
    @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.
     
    chethanv_777 likes this.
  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:
    334
    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. }
     
  12. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    719
    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...
     
  13. LarStudio

    LarStudio

    Joined:
    Nov 27, 2021
    Posts:
    2
    Thank you RazorCut
     
  14. ArifiAli

    ArifiAli

    Joined:
    Apr 21, 2022
    Posts:
    1
    RAZOR CUT THANK YOU SO MUCH
     
  15. chethanv_777

    chethanv_777

    Joined:
    Oct 26, 2022
    Posts:
    6
    This helped me
     
  16. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    120
    Hey, did you solve your issue?
     
  17. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    334
    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.
     
    noor_games_commercial likes this.
  18. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    120
    Good. I have been searching and found this working drag and drop script editor https://gist.github.com/bzgeb/3800350.
     
    Tony_Max likes this.
  19. adreamvoyager_unity

    adreamvoyager_unity

    Joined:
    Oct 16, 2018
    Posts:
    14
    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.
     
    noor_games_commercial likes this.