Methods instead of Sensors

Hey community,

is it possible to code BGE scripts more like scripting in Unity/Godot? I mean calling events or overwrite methods instead of adding sensors and connecting it to a script via Blenders GUI?

Yes. use the Python controller to activate scripts. Scripts for the BGE are written in Python.

Sorry, but I meant inside a script.

for example, in unity you have methods like Update() or OnTriggerEnter() which you overwrite to execute code on specific events.

Try UpBge, it got the py components. They are similar to what you want.
Links: https://pythonapi.upbge.org/bge.types.KX_PythonComponent.html
https://doc.upbge.org/releases.php?id=0.0.6

we also have Collison callback and predraw callback and postdraw callback

a ‘generalized’ sensor could monitor many objects and run logic when conditions dictate using a list it fills


activate =[]
def Ray_Ccd_collision(obj):
    #command meat

commandDict = { 'Ray_CcD_collision':Ray_CcD_collision , etc....}
senslist = [ ['Ray_CcD_collision', object1],['near',object,prop] ]

for entry in senslist:
    command = commandDict[entry[0]]
    return = command(entry[1])
    if returned!=None:
        activate.append(returned)


one could use collision callbacks, but my solution is to spawn a object that is a rigid body and then suspend dynamics / rigid body sim etc depending on the obj being bound to it, and parent the object to it and use a Collison sensor in the object.

added = own.scene.addObject('CollisionSensor',own,0)
added.replaceMesh('shapeboundname',1,1)
v=obj.worldLinearVelocity.copy()
obj.setParent(added)
obj.worldLinearVelocity=v