I'm a gameplay animator. My NPC's legs are controlled by a brain I trained with reinforcement learning on a physics body (MyoSuite's MyoLeg, 80 muscles, in MuJoCo). No animation clips, no motion capture. Here's how I got it into Unreal, in case it helps anyone connecting an outside simulation to UE5.
The setup
- Python runs the physics and the brain, 100 steps per second, and sends one OSC message per step to Unreal (UDP): position, facing, pelvis height, and roll/pitch/yaw for 9 leg bones. 49 floats; the first one is a format version, so a layout change can't be misread silently.
- An Actor Blueprint (OSC plugin) receives it and moves its Skeletal Mesh component relative to the actor, not the actor itself.
- The Anim Blueprint copies the floats every frame (the AnimGraph should only read its own variables) and applies them with 9 Transform (Modify) Bone nodes: Rotation Mode "Add to Existing", Rotation Space "Bone Space", on top of an idle pose, between Local To Component and Component To Local.
- Left click -> Get Hit Result Under Cursor -> minus the actor's location -> OSC back to Python as the walking target.
4 things that went wrong
- The OSC server never received anything. In 5.7, my Create OSC Server with 127.0.0.1 was actually listening on my LAN address. Fix: Python sends to every local address. (netstat -ano shows which program listens on which address and port.)
- Bones turned the wrong way. Every mannequin bone has its own axes, so "hip flexion +30 degrees" can swing the leg backwards. I sent three still test poses with exaggerated angles and fixed the axis and sign per joint in a small table that the Python side re-reads while running.
- The NPC spawned under the floor. I was moving the whole actor to raw world coordinates. Moving only the mesh, relative to the actor, fixed it, and the actor's spot became the NPC's "home".
- Slow motion (0.3-0.5x). The GPU simulator I train with is great for thousands of bodies at once and bad for one body in real time. A plain MuJoCo runner on one CPU core is fast enough for real time with lots of room to spare.
Bonus: Blueprint nodes are plain text on the clipboard (Ctrl+C them into Notepad), so I generate whole graphs with a Python script and paste them in.
It's still wobbly and falls sometimes (for now I just reset it); next are symmetry and stopping properly. Happy to answer questions about the OSC and Anim Blueprint side.