Resources.Load doesn't work

Hello!

I spent hours trying to achieve what I want, but it doesn’t want to work.

I’m trying, to Resources.Load() an image from my Resources directory and display it on an Image then.

This works, prints “Texture loaded”:

		var texture = Resources.Load<Texture>("Categories/Matchsticks/1");
		if (texture != null) {
			print("Texture loaded");
		}
		else {
			print("Missing image file");
		}

So yes, the path is correct, the file is present. But… This doesn’t work, prints “Missing image file”:

		var texture = Resources.Load<Texture2D>("Categories/Matchsticks/1");
		if (texture != null) {
			print("Texture loaded");
		}
		else {
			print("Missing image file");
		}

The only difference is Texture to Texture2D

I need to load that texture in order to create a Sprite (Sprite.Create(Texture2D, Rect)) and display the image, on Unity, Android and IOS, explaining why I use the Resources folder and Resources.Load()

I did try with other methods, they all fail

var texture = Resources.Load("Categories/Matchsticks/1", typeof(Texture2D));

var texture = Resources.Load("Categories/Matchsticks/1", typeof(Texture2D)) as Texture2D;

Ok, after more than 7 hours fighting, I found the solution… And it’s pretty dump… We copied these images back and forth, and somehow, the file lost their texture types…

Click on the image and make sure that the import settings texture type is correctly set

alt text

Loading a resource is then as easy as:

var texture = Resources.Load<Texture2D>("path relative to Resources folder to the image, without extension");
if (texture != null) {
    Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
}

I’ve seen this question many times on here and stackoverflow, never found the answer… This topic put me on the track though: c# - Resources.Load<Sprite> returns null only for certain files - Stack Overflow.

Hope my self answer helps others!