Get individual sprites from a spritesheet (Texture2D) with Sprite Mode multiple inside a script

I have imported a spritesheet (Texture2D) with Texture Type set to Sprite (2D and UI) and Sprite Mode set to Multiple. Is there a way to extract individual sprites from the spritesheet inside a c# script?
Maybe something like this

Sprite sprite = spritesheet[i];

or getting a List from the spritesheet

List<Sprite> sprites = spritesheet.Sprites;

I have searched the scripting API but could’t find anything.

In the editor you can just load them all with methods in the AssetDatabase class.

In a build you can:

  • drag them all into something / somewhere

  • put them in a Resources/ folder and use Resources.LoadAll();

Always use Resources.Load<T>(), never use Resources.Load() as T

And the same goes for Resources.LoadAll<T>()

Generally you want to avoid writing code that is simply waiting to mysteriously fail simply by the future appearance of an identically-named file of a different type.

1 Like