- Home /
Resources.Load sprite returning null
i'm trying to change the sprite of a gameobject that acts as the background to my game but the sprite is being changed to none for some reason. The sprite i'm trying to access is set as a sprite in the inspector and it is located in the resources folder and i'm pretty sure i'm using the right path name.
I'm using the following code:
background.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Sprites/misc/backgrounds/wallBackground1.png");
Any help is appreciated :)
Answer by _Yash_ · Aug 24, 2016 at 11:04 AM
drop the file extention .png
background.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Sprites/misc/backgrounds/wallBackground1");
Ah yes, that's got it working. Thanks for correcting my silly mistake!
Answer by Melontxo88 · Jul 17, 2017 at 01:20 PM
public Image myImage;
myImage.sprite = (Sprite) Resources.Load("YourFolderName/YourSpriteName",typeof(Sprite));
Your answer
Follow this Question
Related Questions
Resources.Load have a bad performance 1 Answer
Sprite Renderer unlit on devices when using Unity 5.2.0 0 Answers
How to choose a size/resolution for the sprites used as game assets in Unity2D ? 2 Answers
Sprite Mask Render Issue 1 Answer
Why do my GameObjects have a flickering line above them? 2 Answers