Procedural skeletal animation

Hello, I’m interested in trying a project for myself, which is mainly about pricedural animation of characters. I thought I’d like to use Unity, as I had some experience with it in the past.

I also have some experience with OpenGL programming, and I know how rendering pipeline works there. I’d like to know if I can use Unity to manually control the bones of the skeleton-based rig?

I did a brief search, but didn’t find any good tutorials or materials on the subject, so I thought I’d straightaway ask that. I guess somebody probably did it or will at least point me in the right direction.

What I want to ideally do is to procedurally build animation keyframe data through script (Java) and pass it to the videocard to render.

I am NOT interested in visual animators and animation building tools that come with the engine. I want to TELL the program to rotate a bone by a quaternion in certain time, combine it with data for other bones, and then generate the frame data for this movement.

1 Like

Hi @Akuma ,

There’s documentation etc. out there but you probably didn’t do good enough search queries.

Depending on how low level you want to go, the solution might vary - you could make procedurally your meshes and also create the GameObjects that act as your skeletal structure (bones) with code. There’s plenty of information out there if you just search for Unity procedural mesh generation. Alternatively you could import your meshes, then create the bones and skinning procedurally. Or import mesh, bones and skinning. (after all, you said procedural skeletal animation, not necessarily procedural mesh creation?)

Then you need to assign the boneWeights, bind poses and something else probably to get your skinned mesh moving. But then you have a procedurally created mesh that has skinned weights. After that it’s just a matter of making the bone-objects move.

You probably didn’t mean you want to actually use Java, Unity only supports C# for scripting?

That’s the way I’m aiming for, at the moment.

I’ll leave things like mesh creation for later.

I thought it had either java or C# as an option?
If I’m mistaken - it’s no big deal. Feature-wise and syntax-wise the two languages are almost identical. I used to use C# a lot, but Java is cross-platform so everyone seem to move to it from C#.
Edit: Ah, it was javaSCRIPT. As I said, I’ll use C# then.

Unity supported earlier UnityScript, which was a JavaScript-like language, but it was deprecated sometime in 2017 or so. Unity 2017.2 was the last version that had that support if I remember correctly.

Doesn’t really matter 'coz I don’t know javascript anyway. Shouldn’t be hard to figure out, but I won’t do that.

Could you give me some useful links on procedural skeletal animation though?

How about this one?

In unity every bone is just a transform which you can directly move and rotate around as you wish. It’s basically the same as moving any other object. There’s no need for any Open GL knowledge or pushing stuff to the gpu, that’s all already done by the SkinnedMeshRenderer. I’m also using procedural animations but to make it easier to handle I’m using an IK solver to cut down on the transforms I need to manage. Basically just moving 2 feet and 2 arms transforms and 1 to point the head to the location. Not really complicated stuff.
In unity all you’ll need is an array of the transforms and then the usual transform_.rotation *= … stuff._

The reason I wanted to go a bit low-level is because I am not confident that Unity will handle what I’m about to do optimally.
I basically want to construct keyframes on the fly, a complicated ones at that. For example, imagine that I want to move character’s arms from down-up in 3 seconds time. But at the same time I want to bounce a leg up and down every .5 seconds. And on top of that, mix it with breating animation on a 1.5 second loop.

And I don’t want those animations to be pre-baked - I want to make them semi-random. For example each time arms are rising, they will end up in slightly different spots above the head.

As for IK - I know what it is, but I’ll have to study how it’s done. I currently don’t understand the exact way it’s made and functionality and limitations.

Sounds like you should look into Playables and animation jobs, which are designed to solve problems like that.

1 Like

Thank you all for suggestions, I’ll definitely look into all of that