It's my first time working with animations in Unity. I have one animated character (One of the character animation tutorial), and I know that I can access to the keys of the animation by scripting, i have to access to the animation clip, then to the animation curve and from this point I can access to the keys.
The point is that usually, animations interpolate between some clips (runnung, walking, idle) and I don't know how to access to the current animation clip thay is playing at that moment.
If this could help, my final idea is make a physical object follows the joints in a kind of dynamic animation, but for this purpose i have to know where is the next keyframe that the joint is going to go.
I hope anyone can help thanks!
Due to optimizations in how Unity handles animation, there is no way to obtain the animation curves of an animation clip at runtime.
You say that you need to know where the next keyframe is going to go. Is it important that you know the future position of the joint, or is it fine to just always know the current position?
If you just need the current position, you can just follow the joint itself without having to deal with animation curves at all. You can easily get access to the position of any joint at any time - the joint is just a Transform, and you can query the position of that transform. You can make your physical object follow that transform.
If you need to know the position of the joint at some other time than the current time, then things get more tricky, since you can't access the animation curves at runtime. If you really need to go this way, you could make a script which at editor time copies the curves you need into some variables in your script, so you can access them from there at runtime. You can access curves at editor time using the AnimationUtility. However, I would only recommend this approach as a last resort if there's no other way to do what you want.
I'm really not sure what you want to do, but it sounds to me it's like syncing an object movement after another object's animation.
While I bet this can be done through scripting, I think you're just looking at the wrong direction on how to do it. I'm also new to animations with Unity, but these two links helped started thinking in unity's way on how they work.
So, back to the question, if I got it right, I believe instead of syncing them to each other you should simply temporarily attach (joint) them together. It would be pretty much like a player picking up an object and sticking with it. There are simple ways of doing this.
Sorry for not providing any examples on this, for now. Maybe I'll add later.