Resources.Load does not get the correct file

Hey,

I want to change the texture of my GameObject at runtime. For that I use Resources.Load, to load the new texture file. If I press “1” he should change the texture but only removes the current (so that the object is white) but doesn’t add the new one. My texture file is located in “Assets/Resources”. Do I miss something?

if(Input.getKey("1")) {
     Texture foo = Resources.Load("my_texture.jpg") as Texture; // also tried Texture2D
     target.renderer.material.mainTexture = foo; // target is my gameobject
}

Best regards,
emha

Are you sure the file is in the Resources folder?

And did you try swapping out the material instead of the texture?

Yes, ich checked it multiple times. I attached a screenshot.

No I haven’t. How would I do that?

1440910--77358--$Bildschirmfoto 2013-12-04 um 11.18.27.png

You don’t need the extension of the filename. Remove the .jpg

 Texture foo = Resources.Load("my_texture") as Texture;

I found the error :slight_smile: I loaded the resource with the image type. For example: “my_texture.jpg” but you have to load it without the type, like: “my_texture”.

Texture foo = Resources.Load("my_texture") as Texture; // without image type

Thanks for your help! :slight_smile:

EDIT:
THoeppner was a little bit faster :slight_smile: