Unity: How To Add Multiple Sprites To A List In The Inspector (the fast way)

Published December 03, 2019 by Whistling Alpaca Studios
Do you see issues with this article? Let us know.
Advertisement

I encountered this issue very early on when I started creating various custom character animations and I needed to be able to add many sprites to a list object in my unity inspector. I would have to drag each sprite individually into the inspector because each time you click on a sprite, the inspector focuses on that element and the fix is really super easy.

In my example I'll be using my GatherableManager prefab object, and just a note, I like to keep all manager objects that will handle sprites and icons in this manager prefab pattern. It's almost essential if you want to avoid putting stuff in your resource folder. The gatherable manager keeps track of all of my harvesting resources like ore, trees, etc.

Step one: Have your data structures ready to go:

public List<GatherableIconMapper> RockIcons;

Supporting class:

[Serializable]
public class GatherableIconMapper
{
	public List<Sprite> Sprites;
	public int rank;
}

Of course you should note: The Serializable tag is required, otherwise your list will not show up in the inspector.

Step two: Lock your prefab in the inspector

Click that little lock icon in the top right of your unity inspector. This will lock your prefab and prevent it from going away when you click your sprites.

Step three: Drag those sprites

Click, then shift select all the individual sprites you want to add to this list. These are my rank 1 ores so I want all the light green/blue ones:

Then simply drag them over the list you want to add them to. You'll see a mouse with a plus (+) icon next to it, and it'll automatically build that list for you

There you go. You just saved yourself approximately one billion hours of dragging and dropping sprites into a list, congratulations!

Cancel Save
0 Likes 0 Comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Unapproved

Featured Tutorial

A quick tutorial designed to help people who are unsure of how to add many sprites to a list in the Unity inspector.

Advertisement

Other Tutorials by Whistling Alpaca Studios

Advertisement