I try to run a simple python invisible visible toggling python controller module. This works well inside blender, but not in the generated game engine runtime.

I have:

  • a 'Cube' mesh
  • a keyboard sensor named 'VisibilityKey' with 'All Keys' selected
  • a python controller in 'Module' mode with source 'mybpylib.visibilitytoggle'
  • controller and sensor are linked.

In the mybpylib.py file i have the following code:

def visibilitytoggle(o_ctrlr):
    if (o_ctrlr.sensors["VisibilityKey"].positive):
        for _ in o_ctrlr.sensors["VisibilityKey"].events:
            if (o_ctrlr.owner.visible == True):
                o_ctrlr.owner.visible = False
                print("i was visible")
                o_ctrlr.owner.visible = True
                print("i was invisible")

When I inside blender game engine press 'P' the invisible visibile toggling of the cube woks perfectly by pressing any key.

When I 'File / Save As Game Engine Runtime' the game get saved, but when I start the executable the invisible visible toggling does not work.

I am using:

  • Blender version 2.78c (and corresponding blenderplayer)
  • on MacOS X 10.12.5 (sierra)

I am still quit a blender noob. It might be that I miss something simple but I can not figure out what. Any help is appreciated.


  • $\begingroup$ I think that you dont need the loop ´´for _ in o_ctrlr.sensors["VisibilityKey"].events:´´ [blenderartists.org/forum/… (blenderartists.org/forum/…) $\endgroup$ Jul 8, 2017 at 6:45
  • $\begingroup$ @Strapicarus : you might be right. it would work as well. This it just for the Lucky Luke case, when you faster type as the blender engine can process it ; ). $\endgroup$
    – bue
    Jul 8, 2017 at 7:30

1 Answer 1


Monster's hint pointed me towards the real answer: Always look at the console window, when you are working with python. (HowTo is described here: https://wiki.blender.org/index.php/User:Fade/Doc:2.6/Manual/Interface/Window_system/Console_window .) When I was using the Embedded Player in the Blender Game Properties Editor, the console printed out that it not can "import bpy". So I realized that I only have to "import bge" and not have to "import bpy".

The second part to the answer I found in MikePan's answer in this post: Packaging external libraries in the game engine 'Create Runtime'. I work on a Mac and I simply had to copy the python file withe code for the controller into the Content/MacOS/Resources folder of the Save As Game Engine Runtime generated app.

This question and comments are as well related to the topic: BGE: where to place external python modules when exporting for Mac OS X

  • 1
    $\begingroup$ Always look at the console window, when you are working with python. $\endgroup$
    – Monster
    Jul 10, 2017 at 4:31
  • $\begingroup$ Thank you @Monster. As you can see in my edited answer, this was really helpful hint. $\endgroup$
    – bue
    Jul 20, 2017 at 16:22

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.