AssetDatabase.LoadAssetAtPath outside the Assets file.

Hi there,

Just wondering if there is a way to load a sprite outside the Assets file.
I have a folder in the unity game files named “Textures” where i keep all sorts of png files for my textures

int pathStart = line.IndexOf("(") + "(".Length;
int pathEnd = line.LastIndexOf(")");

string path = line.Substring(pathStart, pathEnd - pathStart);
Sprite voxelTexture = AssetDatabase.LoadAssetAtPath<Sprite>(path);
foreach(GameObject voxel in voxels) {
   if( == currentVoxelId) {
      voxel.GetComponent<voxelVariables>().voxelTexture = voxelSpriteTexture;

Each time i run this script the path returns as “textures/voxels/00_texture1.png” which is correct, but it doesn’t load. The only way i can make it load is by changing the sprite path to

Sprite voxelTexture = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/" + file);

And adding the texture files in the Assets file.

Is there a way to load these textures outside the Assets files?

You can only load within the Assets-folder with LoadAssetAtPath.

If you want to load files outside you can, but the files will not be included in the build, you have to copy them manually. Then you can use this to load a texture for example

byte[] bytes = System.IO.File.ReadAllBytes(filePath);
Texture2D texture = new Texture2D(2, 2);

On some platforms you can’t access any path you want, you may have to use Application.persistentDataPath