1
$\begingroup$

I have this piece of code that's meant to start the game engine (and it does so if I just run this on the default screen)...I have a script that generates an environment with planes, spheres, etc. and appended this piece of code on the bottom but I'm getting a poll() context error...I'm in 3d view by default and the below thing should make it run in the game engine...any way to fix this so it actually works?

bpy.context.scene.render.engine = 'BLENDER_GAME'
    for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        override = bpy.context.copy()
        override['area'] = area
        bpy.ops.view3d.game_start()
        break
$\endgroup$
  • $\begingroup$ can you post the error message that is in the console? $\endgroup$ – David Sep 17 '15 at 2:47
2
$\begingroup$

My guess is that you are in edit mode. The bge will only start in object mode.

Adding this line bpy.ops.object.mode_set(mode='OBJECT') to your script will alleviate that issue.

Your edited code:

import bpy

bpy.context.scene.render.engine = 'BLENDER_GAME'

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        bpy.ops.object.mode_set(mode='OBJECT')
        override = bpy.context.copy()
        override['area'] = area
        bpy.ops.view3d.game_start()
        break
$\endgroup$
  • $\begingroup$ hm, I'm still getting a poll() context error... full error message: RuntimeError: Operator bpy.ops.view3d.game_start.poll() failed, context is incorrect $\endgroup$ – Archana Ram Sep 18 '15 at 5:58

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.