Unity 4.3 PRO and sprite packer: Load packed sprite from code ?

Hi all,

I’ve been trough the forum but can’t seem to find an answer. My question is rather basic but no way to find a way to make it work!

I have 3Sprites, located in a “Textures” folder (not located in a “Resource” called folder):
•SpriteA
•SpriteB
•SpriteC

I set a Packing tag “SpriteAtlas” for all three of them.

The thing is the packer won’t pack the sprites as long as they are located under a “resource” folder (I guess this is to avoid all sprites to be taken in the build, it seems logical till here we only need the atlas)

But I would like to get a sprite (to put on a renderer) by code !! how can I access the atlas generated by the sprite packer ?

I tried all this and it failed:

Sprite targetSprite = Resources.Load(“SpriteAtlas/SpriteB”); Sprite targetSprite = Resources.Load(“Textures/SpriteB”); Sprite targetSprite = Resources.Load(“SpriteB”); Sprite[ ] targetSprites = Resources.LoadAll(“Textures”);

Resources.Load searches for resources located in a “Resource” folder, but in this case I cannot have the sprites in a resources folder (since the sprite packer won’t pack)

Any help please ?

Many thanks

I have similar problem and did not find any working solutions in google. Help me please.

Once the sprites are packed, you can add a public variable in your script and add each sprites in the inspector.
public Sprite[ ] mySprites;

Once you’ve added each sprites in the inspector, you can do something like this:
mySpriteRenderer.sprite = mySprites[index]; // using the index of sprite you want