I know that this has been answered on other occasions and always the answer is no, but I would like to know if in the current versions of unity this is no longer a problem.
I want to be able to read runtime the keyframes/curves of the current animation, specifically of a bone, for example the pelvis of the character, the final goal is to draw the route of the chosen bone corresponding to the animation that is being executed.
Maybe there are restrictions for the type of animation, it can be a legacy/humanoid or any other, I just want to know if it is possible.
you’ll need the whole path for the bones, like
bones [4] = bones [3] + “/” + prefix + “Neck”;
bones [5] = bones [4] + “/” + prefix + “Head”;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class getCRCurves : MonoBehaviour {
//gets animation curves for a bone from a clip
//for generic animations
public AnimationClip _clip;
public bool getCurves = true;
//check if the bone name in the clip equals
public string bone = "Hips";
[Header("Curves")]
[SerializeField] public AnimationCurve[] hip;
int i;
public bool doDebug = true;
void Start () {
if (getCurves) {
hip = new AnimationCurve[7];
var curveBindings = UnityEditor.AnimationUtility.GetCurveBindings (_clip);
foreach (var curveBinding in curveBindings) {
if (doDebug) Debug.Log (curveBinding.path + ", " + curveBinding.propertyName);
if (curveBinding.path == bone && !curveBinding.propertyName.Contains ("LocalScale")) {
hip [i] = AnimationUtility.GetEditorCurve (_clip, curveBinding);
if (doDebug) Debug.Log ("curve> " + i + " " + curveBinding.path + ", " + curveBinding.propertyName);
i++;
}
}
getCurves = false;
}
}
}
@dibdab thank you very much for answering
Now I can to draw the trajectory of the bone specified in this case “Hips”, but I have noticed several problems.
The trajectory that I draw is built by the list of 3d vectors of the base bone, is an incorrect way to graph the curves but it works, if someone knows how to graph animationCurves in 3d space please show me how I can do it, I made a search and I found nothing, should be using the mathematical formulas but I think this is not available.
Animation curves only have the local rotation for the other parts of the body (hands, feet), that means that I can not choose their position in the time of the animation.
I followed the path of breadcrumbs and found a [post](Is there a way to extract rootmotion curves from a clip - Unity Engine - Unity Discussions / # post-4090204) where you show how you animate a model superimposed on another using the curves, but I do not understand yet how you achieve this if the curves only offer local position, how do you make to match the positions?
To match the trajectory of the curve and my character I had to move everything to the 0,0,0 position:smile:
you can have references of hands/feet and get their position runtime
or calculate their position from the hip position, with the localrotations (probably)
in that post the blue one is humanoid, the yellow one is generic (animated by curves)
found a way to extract curves from a humanoid animation
[from this editor tool: AnimationCurveTools]
with the getAllCurves method, which is obsolete, but works in 5.6
the animation curves are in different order than the muscles and the root rotation is off yet*
*okay, you just need to put the rootmotion curve values after SetHumanPose
humanPoseHandler.SetHumanPose (ref humanPose);
root.position = new Vector3(getAllCurves.sourceCurves[rootP[0]].Evaluate(timeNow), getAllCurves.sourceCurves[rootP[1]].Evaluate(timeNow), getAllCurves.sourceCurves[rootP[2]].Evaluate(timeNow));
root.rotation = new Quaternion(getAllCurves.sourceCurves[rootR[0]].Evaluate(timeNow), getAllCurves.sourceCurves[rootR[1]].Evaluate(timeNow),getAllCurves.sourceCurves[rootR[2]].Evaluate(timeNow),getAllCurves.sourceCurves[rootR[3]].Evaluate (timeNow));
Hi. I am not sure if this answers the question completely, but if all you need is the value of an animation curve then you can use this obscure fact
“If you have a curve with the same name as one of the parameters in the Animator Controller, then that parameter takes its value from the value of the curve at each point in the timeline. For example, if you make a call to GetFloat from a script, the returned value is equal to the value of the curve at the time the call is made”
I am trying to create a custom animator, and need to know the object and the property value change of the object binded to it at runtime. But everything is only available through AnimationUtility class. I am thinking to bake the data in editor into my own Animation Clip for use in runtime, but that’s double the data! Ideally I can use Unity’s and access it from their’s!
I’m in the same situation. I need in my final build read some curves from the clip is currently playing at runtime. I’m trying to remap some blend shapes, so reading from current bones or blend shapes being animated is not a solution for me. I need the curve from the clip.
Anyone with an idea?
Dumb way, but if all clips are in your project (i.e. not in an asset-bundle from other projects), then you can create a container class to contain all the curves before you build it to a player.