Analizying animation bones location with Python

Hi

I need to get bone location of an animation asset, but within skeleton space or offset location from root bone.Is this possible ? (i.e. for detecting when foot bone is near the ground)

I could open an animation asset and iterate trough all frames , getting bone transform like this:

myanim = unreal.load_asset(‘/Game/LA_MOVING_TEST2’)
pose = anim.get_bone_pose_for_frame(myanim,‘Hips’,frame_number,False)

but when I print pose transform location it’s obbiously local-space , fixed bone location as offset from parent bone.

1 Like

Well, just in case anybody hits the same problem:

I ended up spawning the animation sequence into the editor, getting skeletal mesh component, then positioning on desired frame (time) and getting bone world location. (I guess there has to be some method somewhere in API to convert local-bone transform to world but I couldn’t find it. Tried with transform_from_bone_space but it didn’t work.

Here’s a code snippet how I finally solved it:

myanim = unreal.load_asset(‘/Game/LA_MOVING_TEST2’) ## Load animation sequence asset
obj_loc=unreal.Vector(-7800,-900,200)
obj_anim=unreal.EditorLevelLibrary.spawn_actor_from_object(myanim,obj_loc,(0.0,-90,0)) ## Spawn animation into game world (Editor)
SK=objanim.skeletal_mesh_component ## Get skeletal mesh reference
playRate=1
animTime=0.1
SK.set_position(animTime,True)
SK.override_animation_data(myanim,True,True,animTime,playRate) ## Set position within animation sequence
bone_loc=SK.get_socket_location(‘rig_LeftFoot’) ## Get bone location
print("Animation time: "+str(animTime) + "- Left bone world location: "+str(bone_loc))
unreal.EditorLevelLibrary.destroy_actor(obj_anim) ## Destroy spawned animation in Editor.

3 Likes

This saved me months of work. Thanks a lot for sharing.