1
$\begingroup$

I need to be able to switch scenes in python code while in game, and I don't mean hooking up a python controller to a scene changing actuator, I need to be able to change scenes without it. Does anyone know how it would be done?

$\endgroup$
  • $\begingroup$ What are the reasons why you think you "...need to be able to change scenes without it." $\endgroup$ – Monster Aug 3 '16 at 5:42
2
$\begingroup$

It does exist in the API, the trick is you have to get the scene first:

for scene in bge.logic.getSceneList():
    if scene.name == 'oldSceneName':
        scene.replace('newSceneName')
        break

API: https://www.blender.org/api/blender_python_api_2_78a_release/bge.types.KX_Scene.html#bge.types.KX_Scene.replace


Another useful 'replace scene' like thing that I have done quite a lot is to end the current scene(s) and then add the new one:

for scene in bge.logic.getSceneList():
    scene.end()
bge.logic.addScene('sceneNameGoesHere')
$\endgroup$
0
$\begingroup$

The BGE API (version 2.77) does not support to switch scenes without an actuator.

The scene actuator is sufficient enough.

  • You will never be able to switch to more than one scene. [dynamic number of switches]
  • You already can dynamically setup the scene to switch to. [dynamic calculation of the target scene]
  • A scene switch will always performed AFTER the current frame (after the actuators where processed). [timing]

Remark:

You can dynamically add overlay/background scenes via addScene(). This is to add several scenes within a single frame without the need to know the number of scenes beforehand. (Otherwise you need n actuators for n scenes to add).

$\endgroup$

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.