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$
1
  • $\begingroup$ can you post the error message that is in the console? $\endgroup$
    – David
    Sep 17, 2015 at 2:47

1 Answer 1

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$
1
  • $\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$
    – 29374819
    Sep 18, 2015 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .