How to add another action using python in upbge?

Hey guys

i want my character to do multiple action on top of current activated action ,
and without use of multiple logic bricks ,

right now i am playing regular action actuator using this code

if buttonA:         #button pressed

    own.playAction('action01',1,100, layer=0, play_mode=logic.KX_ACTIONACT_LOOPSTOP,blendin = 4)

if buttonB:         #button pressed

    own.playAction('action02',1,100, layer=0, play_mode=logic.KX_ACTIONACT_LOOPSTOP,blendin = 4)

how do i overlay action on top of this running action only using python, i am asking only using python because
i have like 70 to 80 actions , so connecting each logic node to multiple actions is not a good solution ,
if you guys have any idea please help me out

Thanks

I think you can do that by changing the “layer” value, lower values have higher priority.

^yes

actions on a lower layer get replaced by those on a higher layer, if a given bone is keyframed. you can stack actions on top of each other easily if they dont use the same channels.

layer does work, i know , but as you said , it replace current animation , what i want is , to overlay new animation on top of currently running animation

suppose one animation is character walking ,
2nd animation is character nodding his head ,

so when i press one button it should start walking ,
now when i press second button then it should continue walking but it should merge the nodding animation with walking animation

with logic bricks we can do that by changing the blend types,
but how to do that with python, without accessing logic bricks

you may have hundreds of actions but i doubt youll ever need to play them all simultaneously.

take an action brick and use it as a slot, with it’s own layer. swap out its values when you need to

#say own == armature
from bge.logic import getCurrentController
own = getCurrentController().owner

#attributes to be swapped on action change
animAttrs = ["frameStart", "frameEnd", "blendIn"]

#list of values to assign to each attribute, per action
animDict = {
    "walk":[0, 60, 4],
    "headnod":[0, 12, 3]
    }

#layer == name of action actuator
#newanim == name of action
def onAnimChange(layer, newanim):
    layer = own.actuators[layer]; layer.action = newanim
    for i, attr in enumerate(animAttrs):
        setattr(layer, attr, animDict[newanim][i])

that way you can swap values out quickly.

and thats the basis of how this setup works. the walk/idle/turn is one layer. the gun holding/pointing is another. the head turning/aiming is a third.

theres a few more steps to ensure smoother blending, but ill spare you the details for now.