Search Unity

Move whole object in an IAnimationJob

Discussion in 'Animation' started by Mockarutan, Nov 22, 2019.

  1. Mockarutan

    Mockarutan

    Joined:
    May 22, 2011
    Posts:
    159
    I'm working on a DOTS based game, and I just switch over from a quite naive hybrid solution for our character animations, to at least do the processing in my own jobs. It's based on the samples here: https://github.com/Unity-Technologies/animation-jobs-samples

    It all works pretty good, but I've run into a problem. Since the approach still needs a Skinned Mesh Renderer, the animated mesh object still can't be a DOTS entity I presume? So I still need set the world position and rotation of a traditional GameObject, or so i seems. But I thought maybe I could move it in the ProcessRootMotion callback? But it seems like I cannot move it at all unless it's SetLocalPosition in the TransformStreamHandle inside of the ProcessAnimation function. My current attempt looks like this:

    Code (CSharp):
    1.  
    2.     private struct TestJob : IAnimationJob
    3.     {
    4.         public TransformStreamHandle Root;
    5.         public NativeArray<TransformStreamHandle> Handles;
    6.         public Vector3 Position;
    7.         public Quaternion Rotation;
    8.  
    9.         public void ProcessRootMotion(AnimationStream stream)
    10.         {
    11.             Root.SetPosition(stream, Position);
    12.             Root.SetRotation(stream, Rotation);
    13.         }
    14.  
    15.         public void ProcessAnimation(AnimationStream stream)
    16.         {
    17.             var moveStream = stream.GetInputStream(0);
    18.  
    19.             var numHandles = Handles.Length;
    20.             for (var i = 0; i < numHandles; ++i)
    21.             {
    22.                 var handle = Handles[i];
    23.  
    24.                 handle.SetLocalPosition(stream, handle.GetLocalPosition(moveStream));
    25.  
    26.                 handle.SetLocalRotation(stream, handle.GetLocalRotation(moveStream));
    27.             }
    28.         }
    29.     }
    But that does not work. So my question is, can I move the hole Character mesh in a proper way via the TransformStreamHandle inside of a IAnimationJob?

    Thanks!