How to create sensors and actuators with Python

Hello, is it possible to create actuators or sensors for objects with Python (instead of logic bricks)?

have you found any solution?

a have similar task: objects are generated from onload-script and i need to setup alot of ShapeActions for them.

This belongs to the Game Engine support forum.

To answer your question:
No it is not. Sensors/Controllers/Actuators are predefined at the object.

If you want a sensor not to perform it’s processing - use states. A sensor will not evaluated if there is no connection to an controller in an active state.

Controllers are executed when they recive a pulse from any connected controller. No pulse - no execution.

Actuators are executed as long as they are active. The are activated with an activation (True) pulse. They are deactivated when they end their task or receive a deactivation (False) pulse.

Content has been removed. MayDev

I hoped that there could be a way of creating Actuators via python programmatically. I prefer messing with code mostly rather than logic bricks.

I had tried to instantiate an actuator class and store it in a variable but it did not happen. Probably as Mr. Monster said it’s matter of the API.

(Now I simply overload a game object with various actuators and then I invoke them and altering their values by script).

Content has been removed. MayDev

There are a limited number of actuator/sensor like functions that do not directly need to have an attached actuator or sensor see the docs here, some are more useful than others, like for example: “send message” or “add scene”. Bizarrely, you cannot remove the added scene without a scene actuator!

The “send message” function is probably the most powerful way of avoiding duplicate actuators and overloading any particular object

Although I am both a Blender and Python Noob, I am not new to programming and I think that the biggest problem I have had, so far, trying to keep track of what bit of code is attached to which logic brick!

(Oh man, structure, structure where is the structure.)

Moguri put together a test build of blender using custom game object classes so you don’t have to use logic bricks. Find out more and get the build here

Content has been removed. MayDev

@MayhemOfHell: I didn’t realise that you could get the sensors and actuators attached to other objects. Handy, cheers!

Content has been removed. MayDev

Perhaps it’s worth putting together a wiki/book of various game engine python/logic bricks tricks/tips/solutions that aren’t so widely documented? Sorry, a little off-topic…

@MayhemOfHell: Would you share a sample .blend of you basic setup using a ‘master’ empty? I think there’s a fair amount about structuring game logic we could learn.

Content has been removed. MayDev

I second both suggestions

Content has been removed. MayDev

Content has been removed. MayDev

Wow! This is amazing, I consider that this is exactly the way to organize a heavy scripted Blender GE project. This example must be polished and published in a new thread, I am sure that it will save the life of thousands.

Thank you very much for this research! :slight_smile:

Content has been removed. MayDev

Haha, it’s a hard habit to break! Also, if you use your own modules saved internally I’ve found that everytime you change something you have to restart blender to get the changes to take effect. Or maybe I’m missing something there?

Cheers for sharing that, good to know other ways of organising game logic. Going to have a play with that as soon as I can!

Content has been removed. MayDev