Here is some code for getting a object and adding it to another scene:

import bge
# to load the scene

#find the scene and object

scenes = bge.logic.getSceneList()
for scene in scenes :
    if scene.name == 'Scene.001':
        player= scene.objects['player']

scene = bge.logic.getCurrentScene()
ob =bge.logic.getCurrentController().owner

When I play it seem that the "player" from the other scene is added in the camera's position of the current scene.

  • $\begingroup$ Welcome to the site :) I've edited your question assuming that you want to add the player at a specific position. If this is incorrect or you disagree with my edits, feel free to edit it again or roll back my changes. $\endgroup$ – gandalf3 Jun 18 '15 at 8:14
  • $\begingroup$ If you add more detail on how you add your second scene to your game, I might be able to give you a better way to access that scene. Instead of looping through the scene list every time. $\endgroup$ – David Jun 18 '15 at 13:34

The add object function works by adding the new object (the first parameter) at the location of another game object (the second parameter).

With these two lines you are specifying that it adds the player the at location of the object your script is on (probably your camera).

ob =bge.logic.getCurrentController().owner

Here is how to fix it.

Add a new empty, parent it to your camera if you need the player always spawning relative to the camera. If you want the player to always spawn in one spot, then do not parent the empty.

Now use the new empty as the location for where you add the player.

empty = scene.objects['Empty']
ob1 = scene.addObject(player, empty)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.