Resource management

Hello!

How are resources managed in the blender game engine and how can I control the process?
I’m talking about things like loading,unloading meshes to/from memory at a specific time and so on.

Is everything just loaded at once when the .blend file is opened by the blenderplayer?

I’ve been playing around… are SCENES used to load resources? Everything in a scene gets loaded when the scene is called… is this right? So changing a scene would unload the current scene and load a new one I suppose?

The BGE is capable of dynamic loading, though I haven’t experimented with it. As to your question, yes, when you load a scene, everything associated with it in the BGE gets loaded, too. Changing scenes doesn’t appear to unload the first scene (at least, not immediately). I’m guessing the BGE holds onto the data until it gets deemed garbage, and then gets rid of it - I seem to recall a garbage collection timer in the User Preferences menu… You can use this to your advantage by switching to every scene at the beginning of the game to make it all load at once, and then switching back to the scenes when you want with no lag in-between (though it will take a lot of ram to do that).

You are right! :slight_smile: I took another look at the BGE python API and:

bge.logic.LibLoad(blend, type, data, load_actions=False, verbose=False)
Converts the all of the datablocks of the given type from the given blend.
Parameters:
blend (string) – The path to the blend file (or the name to use for the library if data is supplied)
type (string) – The datablock type (currently only “Action”, “Mesh” and “Scene” are supported)
data (bytes) – Binary data from a blend file (optional)
load_actions (bool) – Search for and load all actions in a given Scene and not just the “active” actions (Scene type only)
verbose (bool) – Whether or not to print debugging information (e.g., “SceneName: Scene”)