Unity3D loading resources after build

I have many sets of images (PNG) that are placed in different subfolders inside the Resources folder on the Assets of the project. When working on the editor I'm able to load the images from the different subfolders without a problem, by just simply use the Resources.Load() command and providing the path to the specific image that I'm trying to load, such as:

firstLeftCC = Resources.Load("Case2/Left/CC/IMG-0004-00001", typeof(Texture2D)) as Texture2D;

In this example the image "IMG-0004-00001" is placed in the CC folder, and the CC folder is inside the Left folder, and the Left folder is inside the Case2 folder, and finally the Case2 folder is in the Resources Folder.

But after building the project, for a Windows application, when I run the .exe file it doesn't load any of those images. After some research, it seems that the problem is related with the presence of the subfolders inside the Resources, since the path given to the Resources.Load() function to load the image doesn't exist in the build.

I would like to know if anyone knows a solution for this problem, or if it is possible to load the images from a given folder instead of trying to load them from the Resources folder.

Thanks in advance for the help.


Optional method of loading your PNG file during run time. You can leave the Case2 in the Asset Folder during development. After you build for Windows, go to folder the exe built file is. Let's assume it is called Game.exe. There will be a folder called Game_Data in the-same directory the Game.exe executable file is.

Copy the Case2 folder to the Game_Data folder.

It should now look like this .... Game_Data/Case2/Left/CC/IMG-0004-00001.PNG

Now with code below, you can easily read your png files with the code below:

  Texture2D firstLeftCC = null;
    byte[] imageBytes;
    string imagePath = Application.dataPath + "/Case2/Left/CC/IMG-0004-00001.PNG";

    if (File.Exists(imagePath))
        imageBytes = File.ReadAllBytes(imagePath);
        firstLeftCC = new Texture2D(10, 10);

Now you can freely use firstLeftCC as a Texture2D

Note: Unity creates .meta file/folder for every file/folder in the Assets directory. When when you copy the directory,IMG-0004-00001.PNG will have another file called IMG-0004-00001.PNG.meta. You should either NOT place your Case2 folder in the Assets folder during development or you will have to delete these yourself.

Include using System.IO;

Alternatively to Resources.Load, you can load images from a given folder using the WWW class. To do this the URL must use the file:// protocol and contains the path to the files according to your OS.



Need Your Help

Cannot get email from this php form

php html forms email

I'm making a email form on my website.

IdentityCache in Rails 4.2 fails


Rails 4.2.3, IdentityCache gem 0.2.5