- Home /
Resource.Load returns null on sprite
So, I've used this before on prefabs, and it worked. But for some reason I can not get it to return a sprite. So, im using a sprite sheet that has about 100 icons on it. Im attempting to use
Resource.Load<Sprite>(path);
to load up some sprites into a custom class. That wasnt working though. So I moved it a little closer to the object that was going to load the resource, that didnt work either (not that I thought it would) but no matter what I do, it returns null. This is the code
var mSprite = Resources.Load<Sprite>(items[i].item.itemIcon);
I have stepped through the code at runtime with VS, items[i].item.itemIcon is giving "icon_3" which it should. The sprite itself (or the sliced sprite sheet I should say) is located in the root of the Resources foldder. So, im at a loss. Any help would be appreciated.
Answer by Magius96 · Mar 17, 2016 at 09:05 PM
You're using a spritesheet, but your only using Resource.Load. Maybe you should be using Resource.LoadAll instead as that will return a collection of all the sprites in the sprite sheet, then you can check the names of each sprite to find the one you want.
Your answer
![](https://koobas.hobune.stream/wayback/20220612071844im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Loading built-in resources 1 Answer
Change clone sprite when collides with player C# 1 Answer
Black border around 2D sprite 3 Answers