I'm trying to make it so that when the user clicks while the game is playing, it converts the quads of the "Gem" object into tris.

I have the camera with a sensor for the Left Mouse Button connected to a python controller.

The python script is as follows:

import bge,bpy

cont = bge.logic.getCurrentController()
lclick = cont.sensors["lclick"]

if lclick.positive:
    cam = cont.owner
    origMode = bpy.context.object.mode
    bpy.ops.object.mode_set(mode = 'OBJECT')
    bpy.data.objects["Gem"].select = True
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.object.mode_set(mode = origMode)

This seems to fail sometimes depending on what was selected before starting. When it doesn't work, it gives me the following error:

TypeError: Converting py args to operator properties: enum "EDIT" not found in ('OBJECT')

Furthermore, when I exit the game engine, it does indeed show that "Object mode" is the only available mode for the selection, despite the fact that it shows the "Gem" object as the only thing selected (though, it is outlined in a darker orange than usual).

Can this not be done this way in the game engine? Is there a better way to do it?


1 Answer 1


Running bpy.ops operators in the game engine wont work well (if at all),

Best have the triangulated mesh on a hidden layer, and swap in the triangulated mesh when you need it.

Note, if you really wanted you could use LibLoad to convert a mesh while the game runs, and you could also use bmesh to triangulate the mesh, but this is fairly advanced API use, and Id not really recommend it since it wont work in the blender player.


You must log in to answer this question.

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