- Home /
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;
The circle texture has an extension of .tga
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?
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.
Answer by codecranker · Apr 18, 2013 at 10:30 PM
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