Sharing Animations Between Multiple Characters With the Same Skeleton

Is it possible to load animations from one file and use them in another file?
This might be a silly question.

The number of animations is the same for different characters, and they all use the same skeleton.
Is it possible to store the animations in a single file and have all characters receive and use the animations from that file?

Not a silly question at all. :slightly_smiling_face:

Yes, it is possible — but mostly manually.

Since all characters use the same skeleton, you can export the animation keyframes from Blender (or another DCC tool) and then load/apply them to another character that has the same bone hierarchy.
Internally, each bone simply reads its position / rotation / scale keys and applies them to itself.

Demo:
Castle Game Engine\examples\animations\animate_bones_by_code

General workflow

1- Write a script to export animation keys from Blender. (Parent bones and child bones must NOT be exported the same way)

2-Load the keys from a file into arrays (or another data structure)

Each character’s bones must have either:

1-individual behaviors that apply the keys, or

2-one shared behavior that drives all bones

A procedure that:

pushes the keys over time to play the animation

handles transitions between old and new keys (blending) for smooth results :slightly_smiling_face::slightly_smiling_face:

At the moment, CGE already has low memory usage even when loading many animations, so in practice you won’t gain much in terms of memory or performance by doing this.

Where this approach can be useful

Playing partial animations (upper body only / lower body only, etc…)

Reducing the total number of animations

Reducing animation work inside Blender

In the future, I plan to complete a practical example of implementing this method, which may be useful for some special cases.

2 Likes

Thank you for the explanation.

I think managing animations for a large number of characters using this approach—especially inside the Update loop—would be quite difficult. In the provided example, only the neck is animated, but in a real-world animation many bones may need to be animated simultaneously.

Additionally, the number of animations is not small (around 30 animations). This approach may solve the problem for small-scale projects, but for a large number of characters I don’t think it would scale well or remain efficient.

In my opinion, having a property that can receive and manage animations in a serialized form (such as JSON or plain text) would be a much better solution.

Even better would be having a base animation transform that can execute and manage the selected animation directly on the scene.

1 Like

Isn’t there a solution to display the animation this way?

i put demo here in my last post.

1 Like

Hello,

I’ve been busy with some work for a while.
Thank you for taking the time to create and share this demo.

I had some free time today and replaced one of your animations with one of my own.
However, the timing in the animation is not respected, and everything plays quickly and back-to-back.

About the animation timing: in the demo I’m playing the animations at a fixed 30 FPS,
so if your action was authored at a different framerate (60 / 24 / 10 etc.),
it can look like everything is playing too fast.

Also, before exporting, it’s a good idea to bake the action in Blender so it generates keyframes for all frames before export.
This helps preserve the correct timing and avoids issues when the animation has sparse keyframes.

One more thing: if you’re using CastleTransformReference to point to the scene,
try disabling it . In some cases it can make the animation appear to play faster than expected.

If it still doesn’t work, upload a small test case and I’ll take a look.

1 Like

This script helps you bake an Action in Blender.

Just select any Action in the Dope Sheet, then run the script, and you will get a new baked Action
with a name like: **000_**ActionName

After that, select this new baked Action, select any bone, run the key exporter script (CopySelectedBone.py), and it will export all animation keys to a file on disk.

BakeAction.zip (901 Bytes)

1 Like