Continuing animations from last frame in python?

I can’t figure out how to continue the animation from the last frame in python. It’s a simple check box in nodes, but I can’t figure it out in script.

So if I’m running this:

if own[‘variable’] == 1:
playAction(“Animation_ONE”, 0, 299, blendin=10, speed=1, play_mode=1)
if own[‘variable’] == 2:
playAction(“Animation_TWO”, 0, 299, blendin=10, speed=1, play_mode=1)

What is the standard way to achieve the “Continue” check box from the logic bricks in python based animation?

Thank you for your time. I appreciate it.

if you want to continue the animation from any frame, you need a trigger condition to record this frame, it is best to record the frame in the property of the armature[‘frame’] = armature. getActionFrame() then comparing the received frames in a certain range, you can create conditions on python and even write the desired frame number to other properties to start playback from this last number - armature.playAction(“Armature_Action”, armature[‘frame’], 100, blendin=5, layer=0)
for example, a simple condition if the
if armature[‘frame’] in range (1, 50):
armature. action (“Action 1”, 1, 51, blendin= 5, layer = 0)
elif armature[‘frame’] in range(50, 51):
armature[‘last frame’] = armature[‘frame’]
elif armature[‘frame’] in range(50,51) and key.positive:
armature. Action (“Action 1”, armature[‘last frame’], 100, blendin = 5, Layer = 0)
just don’t forget to get frames from the armature get. AtionFrame() and write them to the property, and remember about the layers of the animation being played by default, the animation frame acquisition function captures the zero layer to get other layers, put the number of the layer being played in parentheses of the frame acquisition function

Use KX_GameObject.getActionFrame() & KX_GameObject.setActionFrame() functions together to achieve continuing of animations.

When an animation stops, store the got frame in a variable, then set that animation frame at the saved frame next time it is activated.

1 Like

I saw the same solution in the documentation, but the documentation is severely lacking when it comes to explaining how to actually incorporate these strings of code.

If for example, I write:
playAction(“Animation_ONE”, 0, 299, blendin=10, speed=1, play_mode=1)
Where do I put " KX_GameObject.setActionFrame()"? I can set the frame to a property in the armature, but I don’t know what to do from there.

The animation needs to loop, so I can’t just plug it into the start frame.

@ Villi89
Thanks for the help. I can get the animation frame to write to a property, but I don’t know what to do with the property once I have it. I can’t place it in the start frame because the animation needs to loop.

Am I missing something?

Use a integer game property to drive the animation frame.

import bge

def main(self):

  frame = int(self.owner["Saved_Anim_Frame"])
  self.owner.playAction("Animation_ONE", frame, frame, blendin=10, speed=1, play_mode=1)

And I’m supposed to manually make rules for each and every single possible animation each with a separate end point, loop point, and for compound animations, starting point and dictate where when and how each and every combination loops, updates and starts based on those?

I’m referring to the game engine, not your advice (Which I’m thankful for) when I say there is absolutely no excuse for something to be this complicated. I can literally do old school vertex, rigless, 1970’s animation for the same amount of work.

There has to be a better way… At this point, I’m getting really, really sick of this engine and am about to switch to Unreal.

The help from these forums are the only thing keeping me here. I appreciate all your guys time, care and help. Means a lot. Thanks.

I think it might be time to upgrade to Unreal though… C++ > Python anyway.

Hi if you use cycles animation need create two property - and insert this two property in animation script - own[‘frame_start’] - int, own[‘frame_end’] - int, skelet.playAction(“Action_Cycle”, own['frame_start], own[‘frame_end’], blendin= 5, layer =1) only two property get for you solution for drive animation in cycles