how to get information about current frame of animation

I have 3 actions and I want them to play randomly after each other.
So how to do that? I’ve searched over BGE API and did not find anything helpful

something like

frame = yourgameobject.getActionFrame()


        action_layer = 1
        parent_frame = 30
 
        frame = armature.getActionFrame(action_layer)


        if frame:    
                     
            if frame == parent_frame:
                #do something at frame 30 of the animation that is playing on layer 1

#edit
there is a logic brick for it as well, actuator sensor.

Cotaks
edderkop
Great thanks!

But how to get current armature without directly naming it? I am making some sort of “reusable module” and I am not able to write all armature names for all objects.
I guess this thing I should handle myself :slight_smile: Thanks for pointing me in right direction!

p.s. Interesting, why this shows false when action on layer 0 is actually playing:
http://bgepython.tutorialsforblender3d.com/Action/isPlayingAction

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

print(own.isPlayingAction(0))

The best is to sense the end of than animation rather than arbitrary frame. This will force you to setup the animation end twice (once when you start the animation and when you check).

On logic bricks you follow post#3. Yes, you need one sensor for each logic brick.

On Python you can use isPlayingAction(layer=0)

Thanks!

One more question:
How to update information continously?

I have simple code that controlls animations:
def idlerule(idle_1, idle_2):
if armature.getActionFrame(4) <= 79:
cont.activate(idle_1)
if armature.getActionFrame(4) >= 79:
cont.deactivate(idle_1)
cont.activate(idle_2)

BUT! There is problem: switching between idle_1 and idle_2 is going only when I use mouse or do anything in scene. I mean I cant switch animations right after each other. This is idle this means animations should switch without my interactions

You could also learn from this example: TPS Walk Rig, link- https://blenderartists.org/forum/showthread.php?291532-Third-Person-Shooter-Movement-Example-File

The action actuator will end -> this lets the actuator sensor trigger the connected controllers within the next frame -> activatin ghte next actuator.

With Python … you need to check each and every frame.

I understand this, but how can I check every frame? How to “force refresh”?
And if I will check every frame, will it led to fps drop?

Should I use delay? Will it help?

Monster
Danke :wink:

I have got a better solution.
I wanted to make action without calling armature and, actually, there is pretty simple solution.

http://bgepython.tutorialsforblender3d.com/ActionActuator/Flipper/frame

################ Get the current frame number of the action

import bge module

import bge

get the controller

cont = bge.logic.getCurrentController()

get the actuator attached to the controller

my actuator is named left_Flipper

act = cont.actuators[“left_Flipper”]

get the current frame number

number = act.frame

just call action_actuator.frame and it will return frame without any calling for armature even if your main logic bricks in seporate object

Do you want them to follow plain random?
Do you want to play each one once in a random order?

Here is a demo that plays random actions (turn around x, turn around y and turn around z).

Attachments

RandomlyPlaySequenceOfActionsDemo.blend (412 KB)

HM! Interesting! Really handy advice and nice demo scene! Thanks!