"Build and Run" will load assets fine but running the EXE won't
So these are my Build settings and these are my Player settings.
All I've done was disabling the "Display Resolution Dialog" (even though I had the same error before disabling that).
So if I press "Build and Run" from the Build settings in the first picture, it will correctly load the Resource in the background of MainMenuScene and I'll get this as result:
But if I run the EXE file on Windows, I'll get this as result:
It is strange because "Untitled" and "Press Enter" are both images as well, but they are not loaded as "Resources" in code. The tiled background is loaded using this code from Unity's Forum. I used it so I can easily manipulate the texture to generate that checked pattern.
Is it a known issue? When I was running the game using the Display Dialog, the resources were correctly loaded only under certain resolutions.
Is there any build or display configuration I'm missing?
Answer by hnrqndrd · Jun 08, 2017 at 02:55 PM
Ok, this is confusing. But I figured it out.
I sent my project to Unity QA and they did not have any problems running both through Build & Run and through the Windows' EXE.
I tried to load the background using the fullpath to the file and it worked running it from the EXE. So I decided that I should avoid this alternative code to load external Textures and Sprites. Instead, I changed every reference in code to Resources.LoadAll<T>()
or Resources.Load<T>()
, loading Sprite
and Texture2D
. I had to manage every piece of texture (and sometimes create prefabs) on Unity, which makes importing many new content at once a little hardworking.
I still don't know if this only happened to me, but if anyone else has this issue, there you go.
TL;DR: Give Unity the task to handle resources and avoid loading external content via script.