How to use the Actuator Sensor in Python

I’m having trouble finding information about the actuator sensor. Searching is difficult because it brings up things related to actuators themselves and not the actuator sensor. So I want to get make the actuator sensor trigger after an action ends.
With bricks its Actuator Sensor(with the action)—>Nand Controller—>Do a thing.

How do I do this with Python?

For instance

import bge
from collections import OrderedDict
from mathutils import Vector

c = bge.logic.getCurrentController()
owner = c.owner

ac = c.sensors[“Actuator”]
key =

W = key[]

arm = owner.children.get(‘GameRig’)

frame = arm.getActionFrame()
action = arm.getActionName()


def Action(name, start, end, blend,pri,speed):
if frame == end:
blend = 0


if W:
# ORDER: name, start, end, blendin, priority, speed
Action(‘The Animation’, 1, 43,4,0,1.5)

So if the indentations do show. But say I want the end of “The Animation” to trigger the an actuator sensor to do a thing like

if ac.subjects.count(“The Animation”) ≠≠ 1:
Action(‘The Second Animation’, 1, 30,4,0,1)

Something like that

Thanks for the help everyone.

1 Like
import bge


def main(self):
    if self.owner.getActionFrame() < FRAME_END:
        self.owner.playAction("CubeAction", 0, FRAME_END)
    elif self.owner.getActionFrame() == FRAME_END:
        print("Animation has ended.")
1 Like

Thank you

I am trying to get the code for this set of logic bricks.


Its pretty basic. The cube plays an action then when its done it sends a negative pulse and the actuator sensor triggers the add object torus. There is very little about the actuator sensor in general and less about it in python. Thanks again.

1 Like

This script requires a game property on the object that is running the script. Have the game property be of:
Type: Boolean
Name: INIT
Value: True

import bge

ACTION_NAME = "Action"

def main(self):
    if bge.logic.keyboard.inputs[].activated:
        self.owner.playAction(ACTION_NAME, 0, ACTION_END)
    if (self.owner.isPlayingAction() == True) & (self.owner.getActionName() == ACTION_NAME) & (self.owner.getActionFrame() == ACTION_END) & (self.owner["INIT"] == True):
        self.owner.scene.addObject("Torus", self.owner)
        self.owner["INIT"] = False

Edit: Originally I assumed you’d run the script from the cube spawner that you have, but if instead you’re running it from a different object you’ll need to replace self with the correct KX_GameObject name (e.g. self.owner.scene.objects["Suzanne"]). This is crucial because the self.owner argument in the KX_GameObject.addObject() indicates the location where you want your torus to spawn.

1 Like

You can also identify an Action frame with a frame property.
The Action actuator has a frame property slot which monitors the frames from start to finish.
A sensor property with the frame property will also run something when it = the frame.
Spoilt for choices springs to mind!

Yep. The OP asked for Python only though, I believe.