When a script is run via Script mode through the Python Controller there is no need to have import bge in the script.
Why does running a script via Module mode require importing bge?

Documentation on the blender wiki of the differences between script and module modes.


Why does running a script via Module mode require importing bge?

Because the import statement is the proper way of writing Python code.

The auto-import within script mode is a dirty shortcut. It is still there for backward compatibility. But it is no good design.


  • You always need it to access the the BGE context anyway. (In module mode you do not really need it as you can get access via function arguments.)
  • Bge is not a real Python module. It is a wrapper around the BGE native code.


  • It violates the Python convention to show where objects are coming from (defined by the code or imported from other modules)
  • It hides the fact that this module is imported at all. So a reader will never see an explicit assignment to bge.
  • The bge module should behave like regular Python modules, so it should be imported as any other Python module too.

I strongly suggest to add the import statement in script mode too and ignore the auto-import.

I hope it helps

  • $\begingroup$ ok, so why does bge get auto imported when run as a script, but not when run as a module? $\endgroup$
    – David
    Mar 27 '15 at 17:16
  • $\begingroup$ I can't tell the reasons, because I do not know them. The auto-import was there as I met the BGE the first time (~2.37). The module was called GameLogic at that time and only script mode was available. $\endgroup$
    – Monster
    Apr 1 '15 at 6:00

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.