- Home /
Loading a large number of image resources
I'm writing an application that provides an eye test on an Android tablet. The application requires around 280 images which in total are around 60mb. I've placed these images in the Resources
folder and I tried loading them all using the LoadAll
method of the Resources
class...
Sprite[] arr = Resources.LoadAll<Sprite>(folder);
// organise the loaded sprites
This works well with a small number of images, but when my application tries to load them all it is automatically switched to a background task on the Android tablet and I can't keep it in the foreground. I'm not receiving any error messages when I try to debug the application in Android either. Can anyone suggest a reason for this behaviour and a possible fix?
This is a complete guess, but perhaps Android is setting a task to background if it considers it "unresponsive" after a specific time. Perhaps try another way; load them in smaller batches and then let the frame update so that Android knows the program hasn't stalled. You could either iterate through a list of images using something like Resources.FindObjectsOfTypeAll, or you could arrange your images in batches in subfolders and LoadAll each subfolder. Loading them individually or as small batches in a co-routine would permit the occasional frame update to let Android all is progressing. Just a wild guess though.
Thanks for your reply! I really like the idea of using a co-routine to load smaller batches. Do you know if it's possible to do this with Resources.FindObjectsOfTypeAll
without arranging my images into subfolders? I'm guessing it would work like Resources.LoadAll<type>
and take a long time to execute?
FindAllObjects just creates a list of objects without loading them. $$anonymous$$ind of like getting a directory listing of a folder. So it should be pretty quick. You can then iterate through that list, loading the images as you go. You could arrange your loading loop such that it loads (say) 20 images at a time, before yielding to a frame update. This is also your opportunity to make a loading feedback progress bar for your users :-)
https://docs.unity3d.com/ScriptReference/Resources.FindObjectsOfTypeAll.html
Your answer
Follow this Question
Related Questions
convert Resources.LoadAll("RPGOBJ", GameObject) to gameobject array? 0 Answers
Picture loaded from resource corrupted. 0 Answers
Best method for memory usage. 0 Answers
Having trouble with LoadAll 1 Answer
GUI layout Label Dimension issue 1 Answer