Python module cannot access the function

I run frequently in this issue when using Python modules that they return this error message: “Error: Python(gameObject), python controller found the module but could not access the function”. It happens very unevenly, so it’s hard to pinpoint what might cause it, but I’ve noticed it happened often when creating a script before saving the blend file a first time, then gets screwed up right after the save.
Another occurrence though was when I edited a script to turn it into a module in an already saved blend project. I converted a bunch of scripts just fine, but this one turned up the error message although everything was good. The only difference with the other scripts is that I changed the original name slightly (on top of adding “.py”) Strange thing is: changing a single character in the name of the text block solves the issue.

Does someone have an idea or explanation as to what is causing this? It would be greatly appreciated.

This happens when you use module mode.

You enter into the field: <module>.<function>

<module> is the module name. A module resides in a file called “<module>.py”. The module needs to be in the Python search path to be found. Within the BGE it includes the text blocks of you current Blender session.

You get the error “python controller found the module but could not access the function” when the module does not has a function <function>.


def showA():

Your logic triggers a python controller in Module mode with field “myDemo.showB”.

As showB does not exist (but showA) in myDemo it can’t be found and the BGE shows me the error:

Python controller found the module but could not access the function - object 'Cube', controller 'Python':
AttributeError: module 'demo' has no attribute 'showB'

You posted just a fragment of the error message. You can find the specific information in the details you did not post.

Be aware, external files are considered first. Make sure your modules have no name that already exist. Example “test”. I got that issues a lot with this name. Therefore call them “demo” ;).

Thank you very much. That last part was what I needed, as I realized there was already a text block of the same name in the same folder as the blend file itself.