- Home /
Resources folder, works in editor, doesn't work in runtime
So here's the deal. I have a script thats supposed to load a texture, Resources/myTexture, into a GUI rect. I test this in editor, and everything seems to be fine. I create a standalone game, and no texture loads. I've cross checked the names again and again, spent a whole day on it, and don't seem to be able to figure it out. This is an edited version of the code:
t = Resources.Load("myTexture") as Texture2D;
Rect r = new Rect(0, 0, width,height);
GUI.DrawTexture(r, t);
works perfectly in editor.... any help on how to figure this problem out would be great. I'll update this post if I figure out anything else
Try adding Debug.Log(t)
after the Load
. $$anonymous$$aybe the texture isn't written into the Resources file?
debugging t.name gives me the right results results, no errors... which means it should be working fine. But standalone still shows nothing.
I've checked and rechecked texture names, directory, etc. Everything is what it should be. I've debugged every step.. I don't get why this should give me an error if it's working fine in the editor. Why wouldn't it find the error in the editor?
Answer by hav_ngs_ru · Dec 29, 2014 at 07:56 PM
Try to GUI.Label(t) in standalone instead of Debug.Log in editor. I guess it would be null.
If it works in editor means that your filenames are right. If it doesnt work in standalone means that you texture is not included to build by Unity.
There are two cases why resource are included to build: it is referenced by some object in scene (or by prefab included to build for some reasons), and it is in Assets/Resources folder. Try to force Unity to include your texture by making public Texture field in some script attached to some GO in your scene and attach (drag-drop) you texture to it. If in this case standalone application will work fine - the only conclusion is "unity dont want to include your resources placed in Resources folder for some reason"... it would be very strange and it will be needed to watch all your project to find issue..