- Home /
Move whole object in an IAnimationJob
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:
private struct TestJob : IAnimationJob
{
public TransformStreamHandle Root;
public NativeArray<TransformStreamHandle> Handles;
public Vector3 Position;
public Quaternion Rotation;
public void ProcessRootMotion(AnimationStream stream)
{
Root.SetPosition(stream, Position);
Root.SetRotation(stream, Rotation);
}
public void ProcessAnimation(AnimationStream stream)
{
var moveStream = stream.GetInputStream(0);
var numHandles = Handles.Length;
for (var i = 0; i < numHandles; ++i)
{
var handle = Handles[i];
handle.SetLocalPosition(stream, handle.GetLocalPosition(moveStream));
handle.SetLocalRotation(stream, handle.GetLocalRotation(moveStream));
}
}
}
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!