- Home /
Resource.Load outside the editor
Hello, I have been reading a lot about Resource.Load() but I still have an error when I deploy the app in my Nexus7. I'm trying to play 60 .png images, sequentially with this code:
dirInfo = new DirectoryInfo(resPath);
secTam = dirInfo.GetFiles().Length;
conSec = new Texture2D[secTam];
for(int i = 0; i < conSec.Length; i++){
if(i < 10){
conSec[i] = Resources.Load("Secuencias/Conejo/Comp 1_1_0000" + i, typeof(Texture2D)) as Texture2D;
}else if(i < 100){
conSec[i] = Resources.Load("Secuencias/Conejo/Comp 1_1_000" + i, typeof(Texture2D)) as Texture2D;
}
}
...
IEnumerator PlaySec(){
playing = true;
for(int i = 0; i < conSec.Length; i++){
conMat.SetTexture("_MainTex", conSec[i]);
yield return new WaitForSeconds(repTime);
}
if(replay){
StopCoroutine("PaySec");
StartCoroutine("PlaySec");
}else {
playing = false;
}
}
I have created a folder called "Resources/Secuencias/Conejo" inside the assets folder where i have put my Images with the name "Comp 1_1_000xx".(xx[00,65])
This code is working in the editor!! I have a OnGUI.Box telling me the length of the Texture2D array conSec[]. When I use the editor the length is 65 but when I deploy the app in the Nexus the length is 0.
What I'm doing wrong?
Thanks to all!!
Answer by Bunny83 · Mar 04, 2013 at 07:08 PM
This doesn't work:
dirInfo = new DirectoryInfo(resPath);
secTam = dirInfo.GetFiles().Length;
conSec = new Texture2D[secTam];
because this code directly accesses the resources folder in your project directory. When you build a game the assets are packed into your game, in your case inside the APK file. You can't access them via the filesystem. The only way is to use Resources.Load and you have to use fix assetnames. The content in resources folder is fix and can't change once you created a build. There's no way i know to determine what assets are in a resource folder.
Yes!! You are right, that was the problem. Using an integer for the length of the images array the problem is fixed. Thanks!!
Answer by selzero · Mar 04, 2013 at 06:10 PM
try to simplify the example, can you load just one picture from the resources folder (no subfolders)
Your answer
![](https://koobas.hobune.stream/wayback/20220613093812im_/https://answers.unity.com/themes/thub/images/avi.jpg)