2
\$\begingroup\$

I have a C# script with a public property:

List<Sprite> someSprites;

I would like to add 20 sprites to it, from the inspector window. However, it seems like the only way to do so is to drag one by one. Is there a simpler way to batch fill lists in Unity?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

There are two ways to assign multiple objects:

  1. Editor: Click on the object you want to assign items to. In the top-right of the inspector window, click on the lock icon. Select the objects you want to assign and drag them into the field. Once done un-click the lock icon.

  2. Code: Assign it using someSprites = Resources.LoadAll<Sprite>("Location"); inside Awake().

\$\endgroup\$
4
  • 1
    \$\begingroup\$ A video demonstration of technique 1 is available here. \$\endgroup\$ Sep 16, 2014 at 8:56
  • 1
    \$\begingroup\$ Also worth noting, if you're trying to add your own objects to a list in the inspector, you'll need to make sure they have the attribute serializable \$\endgroup\$
    – House
    Sep 16, 2014 at 14:04
  • \$\begingroup\$ For the first one, if you drag & drop them, they seem to be ordered alphabetically, rather than the order of the dragged objects. Is there a workaround that? \$\endgroup\$
    – Saturn
    Sep 19, 2014 at 19:28
  • \$\begingroup\$ I only understand technique 1 after I watched the video as Kelly Thomas linked. you should drag into the ListField name, not where you normally dropped. \$\endgroup\$
    – Zony Zhao
    Sep 16, 2022 at 8:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .