I packed some sprites into an AssetBundle and uploaded it to my server. The sprites are set to type Advanced, so I can check the read/write enabled box.

When my game downloads it I want to initialize a sprite:

Sprite sprite = (Sprite)Instantiate(bundle.LoadAsset("1.png"));

This is not possible because apparently the asset is not a sprite (but it is...) - it seems like, for some reason, the asset is a Texture2D object rather than a Sprite one (why?). So I have to do something like this:

Texture2D tex = ((Texture2D)Instantiate(bundle.LoadAsset("1.png")));
Sprite sprite = Sprite.Create(tex,new Rect(0,0,tex.width,tex.height));

And that's fine. But I have the feeling this is not how it's supposed to be: why is my asset a Texture2D and not a Sprite already? Why do I need to create a brand new Sprite?


1 Answer 1


Ancient question, but here's the answer: you need to pass an extra type parameter:

var sprite = bundle.LoadAsset("1.png", typeof(Sprite));

I believe that should make sure that any rect / pivot information defined in the sprite asset itself should be retained too.


You must log in to answer this question.

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