- Home /
Resources.Load returns null in a build, but works in editor
Hello Everyone,
I recently updated my project with a new high res art and I am experiencing a problem now. Resources.Load returns null in a build, but works in editor. I tried builds for Windows and Mac that were built using 3.4.2 and 3.5.2.
When I remove half of art files from Resources folder builds are working perfectly. Also I reimported all assets a couple of times and it didn't help.
It would be great to get some direction or hear your thoughts about this problem. Any help will be appreciated.
Thank you very much,
Nikita
Update #1: Any clues? I would really appreciate some help in here.
Please show the line of code where you load the resource :)
Is the actual art named Images and place directly into the Resources folder? Sounds like you want,
Resources.Load("Images/"+myArtsName);
"Images" from the line above is an xml file, that's loading in the first place. And it works in the editor. For example I have a test script that executes perfectly in the editor, but doesn't work in a build.
if (Resources.Load ("Images") != null){
Debug.Log("Images.xml is loaded! "); // executes in the editor
}else{
Debug.LogError("Can't find Images.xml! "); // executes in a build
}
Without a valid type, I don't think it's going to understand what extension to use. What happens if you strip the .xml extension prior to build?
Answer by jtbentley · Jun 05, 2012 at 02:49 AM
You need to define and assign it appropriately.. For instance...
myMaterial.mainTexture = Resources.Load(("carTextureHires"), Texture2D);
It is fairly well summarised here in the manual
It defined and assigned appropriately because it worked before and when I remove half of art files from Resources folder builds are working perfectly.
If I switch to the previous commit where art files are in a small resolution everything works. I haven't changed anything in the project except replaced art files in Resources folder.
Answer by R_Gordon · Jan 11, 2017 at 08:59 AM
Very late to the party, but I had the same problem (as in, Textures where depicted properly whilst running from the editor, but where null (not found) when executed from the build) and solved it by copying a separate Assets/Resources folder with the relevant Textures inside to the same location where the executable build was located at (e.g. if your build is at C:\Files\Something then you would also have to copy a version of your Assets/Resources folder there).
Hope this helps.
Your answer
Follow this Question
Related Questions
Get folder names during runtime within "Resources" package? 1 Answer
resources not loadable in bulid 1 Answer
Do I need to manually call Resources.UnloadUnusedAssets? 0 Answers
About to gut my use of the Resources folder. What are the best practices going forward? 1 Answer
What does Unity actually do when Loading Resources that already exist? 0 Answers