KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
66 stars 8 forks source link

Toggling root motion for each individual Animancer layer #276

Open TigerHix opened 1 year ago

TigerHix commented 1 year ago

Is it possible to enable root motion for one individual Animancer layer only? Or - alternatively - is it possible to read root motion frames from an AnimationClip at runtime, so that I can apply those root motion manually?

Thanks!

KybernetikGames commented 1 year ago

The easiest way would be to set the import settings of the animations you want to ignore to not have root motion in the first place.

In theory, Animated Properties could read the root motion curves of anything, but they currently only work on the overall output which doesn't help you. Animancer doesn't currently have a way to let you insert them between a state and its layer or between a layer and the layer mixer to read from a specific part of the graph.

TigerHix commented 1 year ago

Unfortunately, my use case is that the animation clips do contain root motion data but I want to toggle them on or off at runtime (those animations are provided via AssetBundles).

I'm curious how does animated properties work from a technical point of view. Is it technically possible to read root motion curves from Playables API / Animation API at runtime? Or it's just not a thing in current Unity?

KybernetikGames commented 1 year ago

An Animated Property creates a Playable which runs an animation job which reads the value of a particular curve. It doesn't get access to the actual curve, just the value of the curve at the current time each frame.

Animancer inserts those Playables between its root and the output of the graph so the value they get is the blended result from everything in the graph.

Those Playables would work the same if connected somewhere else in the graph, such as between the layer mixer and a particular layer to read from only that layer or between a layer and a single state, but unfortunately Animancer doesn't support that. For example, when a state's Weight reaches 0 it gets disconnected from its parent then when the Weight increases it will connect itself again, but it wouldn't know what you had that extra Job Playable between it and the layer so the extra Playable would get lost. It's definitely a solvable problem, I just haven't prioritised it because cases like this are so rare. The main challenge would be coming up with an implementation that minimises the performance cost to people not using that feature.