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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Referencing a lot of assets at once

Discussion in 'Scripting' started by ddbrown30, Jun 24, 2020.

  1. ddbrown30

    ddbrown30

    Joined:
    May 19, 2020
    Posts:
    9
    Is there a built in way to populate an array or list on an asset with a bunch of references without having to do it one by one? To be clear, what I've been doing is adding an array param, like this:

    Code (CSharp):
    1. public MyData[] AllTheData;
    Then in the editor, I set the array size to the size I want and then one at a time, I grab each data asset and drag it over. What I'm hoping for is something where I can multiselect items or maybe even drag a folder onto the parameter and it will automatically resize the array and add all the values.

    Is this something that Unity can do (with an implied, "without a custom editor")?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Yes it can! Steps:

    1. select the thing with the array of items public field
    1a. optionally clear the array to 0 items
    2. lock the inspector window (tiny lock, upper right corner)
    3. go browsing for all the things, either one at a time or all at once or in bunches, drag them into the locked inspector
    4. unlock your inspector window

    Don't forget step 4. It's really baffling if you do!
     
    ddbrown30 likes this.
  3. ddbrown30

    ddbrown30

    Joined:
    May 19, 2020
    Posts:
    9
    Nice. Thanks!
     
    Kurt-Dekker likes this.