Load 2D Textures with Resource.Load doesn't work

Hi,

i want to change a texture of an mesh if something happend in my script.
I use the following code for loading a jpg. das 2D Texture but it doesn’t happen.

Texture2D oil_fund;

void Start () 
{
oil_fund = (Texture2D)Resources.Load("Resources/oil_splash.jpg");
}

...

renderer.material.mainTexture = oil_fund;

Do You have an idea why my .jpg isn’t loaded ?
The picture is located at Assets/Resources/oil_splash.jpg

My guess: Since the function is “Resources.Load” i doubt that you have to type in “Resources/oil_splash.jpg” since it is already looking in resources folder. Also, image types (.jpg, .gif, .jpeg) are to be ignored. Try

Resources.Load("oil_splash");

Ignore this answer if you have Resources folder inside your Resources folder :slight_smile:

Try setting the type you want:

oil_fund = Resources.Load("oil_splash", typeof(Texture2D)) as Texture2D;

If it does not work then double check your spelling of the file and the Resources folder. It has to be exact. It is case sensitive as well. So the Resources folder needs an upper case ‘R’.

Also make sure, that you do not enclude the filetype. So DON’T do this:

oil_fund = (Texture2D)Resources.Load("Resources/oil_splash.jpg");

But do this instead:

oil_fund = (Texture2D)Resources.Load("Resources/oil_splash");

I am not an expert and only started coding in C# a few moths ago, but when I was having this problem removing the filetype helped.

try this I promise this would work
{
string address = Application.dataPath + “your local address”; or {string adress = “Resources/oil_splash.jpg”}
byte byteArray = File.ReadAllBytes(@address);
Texture2D pic = new Texture2D(12080,1024);
bool check = pic.LoadImage(byteArray);
if(check)
print(“done”);
}
i had same problem and finally i read bytes and then pass it to Texture2D ,try this I promise this would work
{
string address = Application.dataPath + “your local address”; or {string adress = “Resources/oil_splash.jpg”}
byte byteArray = File.ReadAllBytes(@address);
Texture2D pic = new Texture2D(12080,1024);
bool check = pic.LoadImage(byteArray);
if(check)
print(“done”);
}
i had same problem and finally i read bytes and then pass it to Texture2D
,try this I promise this would work
{
string address = Application.dataPath + “your local address”; or {string adress = “Resources/oil_splash.jpg”}
byte byteArray = File.ReadAllBytes(@address);
Texture2D pic = new Texture2D(12080,1024);
bool check = pic.LoadImage(byteArray);
if(check)
print(“done”);
}
i had same problem and finally i read bytes and then pass it to Texture2D