Loading in Sprites outside of unity?

I need to load a .png file at a specified location on the computer. In this case im making a way to mod the game i am making and i need to read a string from a file(which works) and find the file at the location and load it to a variable. I was using:
tempGolem.icon = Resources.LoadAssetAtPath(Vars.modsPath + “/” + golems[a][“icon”]) as Sprite;

but it doesn’t seem to find anything. I know everything is spelled right, but when i try to use that sprite its just a white box. Any help?

According to the documentation, Resources.LoadAssetAtPath is deprecated and shouldn’t be used. It was replaced with AssetDatabase.LoadAssetAtPath. However, I’m not sure you’ll be able to use that for modding since it’s only available in the Unity editor. It can’t load arbitrary files off the disk. So I guess it depends on exactly what you’re doing.

That said, you can load a .PNG from anywhere in the file system into a texture using something like this…

using System.IO;
...

byte[] data = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(64, 64, TextureFormat.ARGB32, false);
texture.LoadImage(data);
texture.name = Path.GetFileNameWithoutExtension(path);
...

Then create a Sprite instance using that texture and Sprite.Create.

This likely won’t work in the web player, but if you’re supporting modding I assume that isn’t an issue for you.