Dynamically load images

Hi all,

I’m really stuck with this. I want my game to load images dynamically. I need this because I have an XML where I describe the spaceships. A spaceship has also an image. So when I show the spaceships during the game I load the images dynamically.
So I made a class to load images and I can create a Sprite with the loaded image. Everything worked fine until I checked the app on Android, because on the device I can’t open file normally but I need to use the WWW class because the correct path is of type: jar:file://
The problem is that WWW is asynchronous so I can’t find a way to have my “ImageLoader” class to return the Sprite once the WWW has completed to load the image.
I don’t want to use the Resources folder, if I’m not wrong, that would be terrible for performances.

How Unity developers handle this issue? Please help me I’m 1 day still from crazyness :slight_smile:


Hi @GimbalLock,

Having read your question, it seems like the underlying issue is that you want to be notified / take action, when the asychronous WWW call is completed?

Is this correct?

Yes, correct. I asked also on Unity forum and someone told me there’s absolutely no problem about putting assets inside the Resources folder.

The official documentation says Resources folder can be used if:

  • The content stored in the Resources folder is not memory-intense
  • The content is generally required throughout a project’s lifetime
  • The content rarely requires patching
  • The content does not vary across platforms or devices.

I’m not sure what could be memory-intense. I’d use the Resources folder to store my textures and small images, beside that all other requirements are met, so I really think I’ll go with the Resources folder.

Privacy & Terms