How to add/copy/move objects between scenes in realtime (BGE)

Hey everyone,

quite straight-forward question: How do I add an object into a scene, which comes from another scene?

Two scenes are active, ‘Scene’ and ‘importscene’. ‘importscene’ does NOT have a camera to prevent his objects becoming visible and draining framerate:


from bge import logic
 
contr = logic.getCurrentController()
own = logic.owner
 
scene = logic.getCurrentScene() 
impscene = logic.getSceneList()[0] #first scene is importscene
 
obj = impscene.objects['Cube']
scene.addObject(obj, own,0) #add object 'obj' into scene (='Scene')

The previous script makes my blender crash when ending the game-engine. The funny thing that happens though:
The object IS added into ‘Scene’ its object-list (scene.objects), but is NOT visible in ‘Scene’.
Instead it is added (visible) in ‘importscene’, which can be recognised by the camera-angle and (lack of) lighting (importscene has no lights).

It seems that the ‘.addobject’ does import the object to object-list of the scene that calls it, however it add’s the object visibly in the scene where the object is. This probably causes it to crash when ending it.

Is this a bug? Or am I doing something forbidden?

Ps. I do know about LibLoad(), however, this imports all the objects not only into the memory, but also visible into the scene. That’s why I try to use an importing scene without camera to act as a portal for imported objects via LibLoad(). This way it does not affect the framerate (besides loading of course).

Try linking the objects in one scene to the next. The problem is if you’re using the other scene to dynamically add objects to the scenes…

Problem is that I want dynamic loading, to support eventual newly added models, and import these by python. Although thx for the heads up, I found a solution! It’s in the layers…

Although this doesn’t solve this ‘bug’ (if it is one), it works like a charm… To import objects from other .blends, without directly adding them into your scene (so only put them into memory):

  1. use LibLoad() to import the .blend
  2. make sure the imported .blend has its objects on a invisible layer (duh!!!) so it doesnt show when only imported
  3. use scene.addObject(…) instead of the logicBrick ‘edit object’-actuator. It does not work with LibLoad

It was so simple, yet I broke my head on it half a day…