Calling Resources.Load on a Texture is returning null

Hello,

I’m trying to load a Texture from the Resources folder but it keeps on returning null.

t = (Texture)Resources.Load(“Circle”) as Texture;

enter image description here

The circle texture has an extension of .tga

enter image description here

Not that I think it's the issue, but you're doing some overkill on the type casting. Remove the (Texture) type cast from the line once since you're already using the as keyword, which almost does the same thing .... but not really. In either case, having both probably isn't a good idea.

And your "Circle.tga" file is in the top level of your Assets/Resources folder?

Yes it is.

So, just verifying, the path to your file is Assets/Resources/Circle.tga? That should work.

That is indeed the path, I even checked the spelling of everything.

1 Answer

1

I dont think so you can do ‘as Texture’. Casting it with ‘(Texture)’ should work.

See the MSDN documentation to know differences between ‘is’, ‘as’ and () types casting in C#. Its confusing in the beginning.

I also belive that the as-cast might be the problem, but in addition, like @Yokimato mentioned, you should use the Load function that takes a type parameter. You almost never need the type "Texture", in 90%+ of all cases you want to use Texture2D

Thank you from 2018. You help me a lot :)