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\$
5
\$\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().

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ A video demonstration of technique 1 is available here. \$\endgroup\$ – Kelly Thomas Sep 16 '14 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\$ – MichaelHouse Sep 16 '14 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\$ – Oxide Sep 19 '14 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.