Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Resolved About reading animation result from previous output in playable graph

Discussion in 'Animation' started by silver_gp, Jul 6, 2021.

  1. silver_gp

    silver_gp

    Joined:
    May 11, 2015
    Posts:
    5
    Hi, every one.
    I have encountered a problem. I am using playable graph to add IK to my character, and I still want to use the animator state machine. So I create another another graph containing a output and connect it with an playable job which implements IAnimationJob
    upload_2021-7-6_14-22-51.png
    The Animation Script node here is the CCDFaceToJob, here is the code:

    Code (CSharp):
    1. public struct CCDFaceToJob : IAnimationJob
    2. {
    3.     public bool Enabled;
    4.  
    5.     public void ProcessRootMotion(AnimationStream stream)
    6.     {
    7.     }
    8.  
    9.     public void ProcessAnimation(AnimationStream stream)
    10.     {
    11.         if (!Enabled)
    12.         {
    13.             return;
    14.         }
    15.      
    16.         for (int k = 0; k < SkeletonHandles.Length; ++k)
    17.         {
    18.             TransformStreamHandle handle = SkeletonHandles[k];                                  
    19.             Vector3 pos = handle.GetLocalPosition(stream);
    20.             Quaternion rot = handle.GetLocalRotation(stream);
    21.             handle.SetLocalPosition(stream, pos);
    22.             handle.SetLocalRotation(stream, rot);
    23.         }
    24.     }
    25.  
    26. }
    It is just a test, but to my surprise, the animation of the character freezes.
    The animator is now playing the stand animation, and I think the input animation stream in the code should be the result of the animator, but it freezes at a frame of that stand animation.
    So I remove the SetLocalPosition and SetLocalRotation from my code, the animation works well.
    So can somebody tell me right way on how to use the result of the previous output? I know there is an AnimatorControllerPlayable, but there will be many outputs in the graph, and next output will read the result of previous output.
    Thank you very much!
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,769
    Just use the Animation Rigging package. Or if you don't want to use it for some reason, look at how it sets up its graph.
     
  3. silver_gp

    silver_gp

    Joined:
    May 11, 2015
    Posts:
    5
    Thank you very much. In the animation rigging package, I have found there is an extension method called SetAnimationStreamSource. Problem solved, thank you!
     
unityunity