Reputation: 176
I'm currently working on a project in Unity which requires accessing images from a "Resources" folder and loading them as Sprites, for use during runtime.
The sprites in question aren't needed until the user opens a particular window. Only then they are necessary. The thing is, there are 150+ images (resolutions between 120x120 and 512x512) to be accessed, and only one image at a time will be shown (at any moment) during the execution of the game.
So my question is: Which option is better from an optimization standpoint?
To load all images as sprites into variables at the beginning of the game and then use them as they are necessary?
Load the images only when they're necessary?
Possibly important info: I'm using Resources.Load() to access all sprites I need
I don't know if the question has a "linear" answer. If the question is difficult to understand, or isn't answered as easily as I thought, please inform me.
Thank you in advance.
Upvotes: 0
Views: 1092
Reputation: 2853
I'd say use something like Texture Packer to put them into a single sprite sheet, that way you are loading a small number of large images, which typically runs faster than a large number of small images. Then you can piece it out as needed. You'll see increased performance since you're sending less to the GPU every frame too.
As for the options you gave though, I'd favor pre-loading the images rather than waiting until they are needed. Unless you are super concerned about saving space, better to make the scene-load slightly longer (when everything is frozen anyway, and gamers are familiar with loading screens at this point) than to wait until the player is already in the game, engaged, and suddenly they have to break flow for a second and figure out if the game just froze. They won't know what you're doing and it'll just detract from the experience.
Upvotes: 1