Hi there
i´ve a small problem…
I created this folder structure:
Project_Folder/Assets/Resources/Tilesets/
Now i wanted to load a Tileset (a PNG File) from this folder via:
Texture actualtex;
[...]
actualtex = Resources.Load("Tilesets/" + tilesetname) as Texture;
tileset_size = actualtex.width;
And all i got is a
NullReferenceException
UnityEngine.Texture.get_width
I printed the actualtex, tilesetname…etc to the console.
The “tilesetname” is absolute correct (!) and a File with that name exists in the known folder.
What am i doing wrong at loading this texture?
Ps.: I´m using C#
Make sure that your path does NOT include the .extension, in which your case, *.png .
Resources.Load("Tilesets/PNGNameNoExtension");
Hi, try this one.
string texture = "Assets/Resources/Textures/Turner.png";
Texture2D inputTexture = (Texture2D)Resources.LoadAssetAtPath(texture, typeof(Texture2D));
Using a lowercase path solved the issue for me.
I had a file called “EE.png” under Resources (Assets\Resources\EE.png)
It did not work for me to use this code:
Resources.Load("EE",typeof(Texture2D)) as Texture2D
But it worked fine with a lowercase path/filename
Resources.Load("ee",typeof(Texture2D)) as Texture2D
It may be worth a shot to try to lowercase the path before trying to access the file. The “.ToLower” string extension may be useful for that.
as a note if there are special characters and you are on a Mac then you could encounter this issue with certain file names:
https://forum.unity.com/threads/resources-load-with-special-characters-in-the-file-name-ios-and-mac.372881/
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