timeline marker callback

hello.

i want to use timeline markers to trigger special action in game-mode.
e.g.: when the playhead of the action reaches a marker, i want to stop that animation.

is there a way to attach a callback on timeline markers? or on the actions playhead? or to the action itself? or to the animation_data of that object??

thanks for any hints.

I solved it like this:

using an Always Sensor to trigger a python script:


import bpy
import bge

controller = bge.logic.getCurrentController()
own = controller.owner
    
#doCheckMarker is a Boolean game property    
if own['doCheckMarker']:
    
    # get the timeline markers
    tm = bpy.context.scene.timeline_markers
    markers = tm.keys()
    
    # get the actuator:
    # f-curve actuator storing the current frame into a property named "currentFrame"

    actlist = controller.actuators
    anim = actlist["Anim"]
    
    for mn in markers:
        if own['currentFrame'] == tm[mn].frame:
            # we are on a timeline_marker
                        
            # turn off checking until we are off the marker...
            own['doCheckMarker'] = False
            own['lastStop'] = own['currentFrame']
            
            #do something
            #for example stop the animation
            controller.deactivate(anim)

            break

else:
    if own['currentFrame'] != own['lastStop']:
        own['doCheckMarker'] = True
    

if anybody has a better method of implementing something like this, i would appreciate to know it…

it would be nicer to have a native callback function for this.

cheers