loading objects between blend files

Is there any way to load an object from another blend file while the game is running using python? I would like to store the various assets in different blend files to be loaded in as needed instead of loading them in all at once. Is this something that is possible in the blenderGE?

Save the object in inactive layer, load blend type scene with

Add object to the scene

this ?

appending and linking not run in game

You load from another blend using LibLoad. So you can use this like:

import bge

def onLoaded(status):

    print("Blend file loaded in " + str(status.timeTaken))

bge.logic.LibLoad("path/to/file.blend", "Scene", async=True).onFinish = onLoaded

You can also load in MESH type to your scene by specifying “Mesh” in the LibLoad function, but typically I use “Scene”. You can then access the object in the onLoaded() functions or after it has been called. Hopefully this helps.

Awesome p9ablo, that looks like exactly what I need. Just a quick question, can it import a single object from a blend file, or does it import all mesh/action/scene objects?

EDIT: question answered. thanks Klauser

Check my post above. If you load the ‘Scene’ then you will have access to the object once its loaded. Same idea with only loading a ‘Mesh’, but I don’t think it loads materials/textures etc… if you do it that way. So I would load in the full ‘Scene’ and then add the object in the same way you add all objects, with bge.logic.getCurrentScene().addObject().

would it be possible to load a specific scene from a blend file that has more than one scene, or does it load all scenes in the blend file?

I’m not too sure about loading in different scenes, the best way to find out would be to try it.

Why would you need to load in a specific scene? To me it sounded like you are just loading in assets from different sources, so using different scenes just seems to over complicate the situation. You can load in as many assets as you want from one scene, so using multiple scenes seems messy to me.

am making a top down space game, and my original plan was to store all of the ships in one blend files, and load the specific object group as needed.(this would include information about the ship, mounting points for guns, properties about speed/ turn radius, etc.) since that isn’t possible, I was wondering if I could have the different ships in different scenes, and load the scene for the ship. It’s looking like now I will have to have a separate blend file for each ship, which seems excessive.

No, you can load entire scenes at a time. Simply load them to a non-visible layer, and then use addObject to put them in place.