Create an object in the BGE via python without using an inactive layer I'm using the blender game engine, and I'd like to generate an object each time a key is pressed (i.e. press Space, and a rock will be loaded into a catapult)

My problem is that I am using this object within Morse, which currently doesn't support using hidden layers (everything seems to be put on the visible layer as soon as it is loaded)

Normally I would do something like this:

from bge import logic

scene = logic.getCurrentScene()
rock = scene.addObject("Rock", "Catapult")


Catapult is a mesh on one layer, and rock is a mesh on another. I would then use the logic bricks to make a keyboard actuator that calls this script. This works fine when I run it in Blender (currently using v2.6), but I get an error when running it with Morse:

ValueError: scene.addObject(object, other, time): KX_Scene (first argument): object must be in an inactive layer


Is there any way to generate objects without needing the inactive layer?

Alternatively, is there a way to programmatically move an object from an active layer to an inactive layer?

Thanks
Yes, but only via LibLoad (which likely isn't what your after).

You can use LibLoad/LibNew to dynamically load data, then instance that.

You can load data from another blend file or, you can load an existing mesh (but NOT an object).

See these functions:


http://www.blender.org/documentation/blender_python_api_2_69_release/bge.logic.html#bge.logic.LibNew
http://www.blender.org/documentation/blender_python_api_2_69_release/bge.logic.html#bge.logic.LibLoad