Set object position after scene change using Python

I’m making a game where when you hit a door a colision sensor starts a python script to change the scene and setup new objects. The code below will switch the scene properly but the “Player” is not moved to the position specified, nor is the active camera set. I get the scene with all default settings. Also the final print statement will list the CurrentScrene as the scene I’m trying to leave. Is the scene replaced when I call ‘scene.replace(“Scene”)’ or at the end of the frame? How can I set the positions of objects in the new scene using python?


controller = bge.logic.getCurrentController()
obj = controller.owner
scene = bge.logic.getCurrentScene()

print("You hit the door inside 19, we are here", scene)
scene.replace("Scene")
scene.active_camera = scene.objects["Camera.Player"]
scene.objects["Player"].localPosition = [-10.0, -2.0, 2.5]
print("locations saved, we are now here.........", bge.logic.getCurrentScene())

Watch the timing!

You need to modify the scene AFTER you switched to the scene.
Better use the Scene actuator than it is clear that the scene switch will happen AFTER the current logic frame.

In my eyes this is a perfect example that the API gets cluttered with options that do not have immediate effect. I think there should at least an indicator in the name (for example: “requestReplaceScene”). The documentationis incorrect: “Replaces this scene with another one”. It should be “Replaces this scene with another one. The new scene will be active with the next logical frame”.

Btw. I’m sure there are errors in your console.

Thanks again Monster. I added two lines to use an actuator and update the “scene” variable and got the same results, no camera change, no player reposition and last print line prints the scene I’m trying to leave. I do get two error messages:

  1. “shaders not supported!”
  2. “warning: scene HUD already exists, not added!”

Is there a standard way to tell the next logic frame to do the positioning etc. This code is only run from a collision sensor, it will not be active in the next frame. I suppose I could set a globalDict variable to “doorOpened” and pass the position through that then have my main Python script search for it every frame but that seems wasteful.

Thanks again,
nubie


controller = bge.logic.getCurrentController()
obj = controller.owner
scene = bge.logic.getCurrentScene()

print("You hit the door inside 19, we are here", scene)
#scene.replace("Scene")
controller.activate(controller.actuators["SceneChange"])
scene = bge.logic.getCurrentScene()
scene.active_camera = scene.objects["Camera.Player"]
scene.objects["Player"].localPosition = [-10.0, -2.0, 2.5]
print("locations saved, we are now here..........", bge.logic.getCurrentScene())

HELP PLEASE!

I am not trying to hijack this thread but I think my problem is similar the only difference is I am clueless with python.
I recently discovered the “BGE save as run time .exe” feature and saw the opportunity to make my 3D walk-through a bit more portable.
In other words I am not using BGE for games but rather for 3D visualization. All is working well but now I had a request for a before and after so that the client can see what his home looked like in the visualization and what it will look like after improvements were done. I copied some python off a “fpsgame” blend file I found on the net and used it as my walk character. I tried linking my character between scenes but every-time I activate the set scene actuator my character stands at the original origin. The idea is that when the character moves, that movement must be updated in both scenes. Can you PLEASE HELP!