Using Burst in IAnimationJob

Hello,

How can I make use of Burst inside IAnimationJob when using AnimationScriptPlayable?

Hi, you simply need to add the Burst attribut [BurstCompile] on your animation jobs.

[Unity.Burst.BurstCompile]
public struct TwoBoneIKConstraintJob : IWeightedAnimationJob
{
        public ReadWriteTransformHandle root;
        public ReadWriteTransformHandle mid;
        public ReadWriteTransformHandle tip;

        public ReadOnlyTransformHandle hint;
        public ReadOnlyTransformHandle target;

        public AffineTransform targetOffset;
        public Vector2 linkLengths;

        public FloatProperty targetPositionWeight;
        public FloatProperty targetRotationWeight;
        public FloatProperty hintWeight;

        public FloatProperty jobWeight { get; set; }

        public void ProcessRootMotion(AnimationStream stream) { }

        public void ProcessAnimation(AnimationStream stream)
        {
            float w = jobWeight.Get(stream);
            if (w > 0f)
            {
                AnimationRuntimeUtils.SolveTwoBoneIK(
                    stream, root, mid, tip, target, hint,
                    targetPositionWeight.Get(stream) * w,
                    targetRotationWeight.Get(stream) * w,
                    hintWeight.Get(stream) * w,
                    linkLengths,
                    targetOffset
                    );
            }
            else
            {
                AnimationRuntimeUtils.PassThrough(stream, root);
                AnimationRuntimeUtils.PassThrough(stream, mid);
                AnimationRuntimeUtils.PassThrough(stream, tip);
            }
        }
}
1 Like

Is this the case for 2018.4 as well, or only 2019? For some reason I can’t get an AnimationJob to Burst compile.

Caveat:To [BurstCompile] DO remember to include the refs in the asmdef