• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Loading/Unloading Game Assets

Any tips for efficiently loading and unloading game assets (i.e. sprites, sounds, objects) into memory upon entering/exiting a level?

My current game is level based and I've already organized the sprites, sounds, and objects into separate directories for each level.

For example:
  1. Upon entering the first level: load_assets(Level_1)
  2. Upon exiting the first level: unload_assets(Level_1)

Appreciate any advice!
 

kburkhart84

Firehammer Games
Each asset type has different things you do for this.

For graphics, take a look at texture groups. You generally organize your graphics into these groups. Anything that needs to be available all the time(like the player, GUI, or enemies that appear anywhere) would be in one group. Then anything specific to a level(or level type) would be in another group, and so on for each level. When changing rooms, you run a function that flushes all the graphics out of the GPU. Then you can run the texture prefetch function to load in the sprites/graphics you will need for the next level, before you go there.

There exists a very similar thing for audio. However, it seems that those load on a separate thread, so the game won't freeze while doing it, meaning you will have to use the async event to know when the sounds are loaded before proceeding.

Any other assets take very little memory as far as the specifications(like objects), so you wouldn't be able to mess with loading/unloading those. And actual instances of of objects are automatically handled by the engine, so will no longer be loaded once you change rooms(except for persistent ones).
 
Top