How to load (and display) a texture png from my Resources folder

I’ve been following various pieces of advice but nothing has seemed to solve this problem.
I’d like to set up a sequence of planets, each based on a Planet prefab. I’ve got the planets instantiating and I can customize their size and so on, but I need to specify which surface textures (atmosphere, etc) each will use.

I’ve been using…

_textures.Add(Resources.Load("/Textures/img_surface1.png" ) as Texture);
Debug.Log("_textures[0] = "+_textures[0]);

…where _textures is a List, but _textures[0] is logged as nothing (it doesn’t say ‘null’, the console logs only "_textures[0] = ").

Later, to add the texture to the planet, I do…

GetComponent<Renderer>().material.SetTexture("_MainTex", _textures[0]);

…but the planets just display all white.

I’d like to know what I’m doing wrong. If it’s because I’m loading a png, what’s the alternative? I’ve tried using a jpg. Am I supposed to be loading an actual Unity Texture type? If so, how would I get one external to Unity to begin with? I’ve tried all manner of URLs; with the slash, without; with ‘Resources’ at the start, without; both with a slash and without.

My Resources folder is in the Assets folder of my project and it has a Textures folder where the img_surface1.png image (amongst others) lives.

Is there anything obviously wrong with what I’m doing?

Any help appreciated.
Cheers.

A friendly quote from the documentation

The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.

Change the path from

“/Textures/img_surface1.png”

to

“/Textures/img_surface1”

I had the same problem, and found solution in older question, you should not have the root “slash” and, no extension.
Change the path from
“/Textures/img_surface1.png” → “Textures/img_surface1”

From unity script reference:
“The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.” So: no “.png” at the and :slight_smile:

Hi all, exists some way to avoid write exter al permission to load a png img from Resources?

Greetens