Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using Burst in IAnimationJob

Discussion in 'Animation' started by Deleted User, Sep 24, 2019.

  1. Deleted User

    Deleted User

    Guest

    Hello,

    How can I make use of Burst inside IAnimationJob when using AnimationScriptPlayable?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi, you simply need to add the Burst attribut [BurstCompile] on your animation jobs.

    Code (CSharp):
    1.  
    2. [Unity.Burst.BurstCompile]
    3. public struct TwoBoneIKConstraintJob : IWeightedAnimationJob
    4. {
    5.         public ReadWriteTransformHandle root;
    6.         public ReadWriteTransformHandle mid;
    7.         public ReadWriteTransformHandle tip;
    8.  
    9.         public ReadOnlyTransformHandle hint;
    10.         public ReadOnlyTransformHandle target;
    11.  
    12.         public AffineTransform targetOffset;
    13.         public Vector2 linkLengths;
    14.  
    15.         public FloatProperty targetPositionWeight;
    16.         public FloatProperty targetRotationWeight;
    17.         public FloatProperty hintWeight;
    18.  
    19.         public FloatProperty jobWeight { get; set; }
    20.  
    21.         public void ProcessRootMotion(AnimationStream stream) { }
    22.  
    23.         public void ProcessAnimation(AnimationStream stream)
    24.         {
    25.             float w = jobWeight.Get(stream);
    26.             if (w > 0f)
    27.             {
    28.                 AnimationRuntimeUtils.SolveTwoBoneIK(
    29.                     stream, root, mid, tip, target, hint,
    30.                     targetPositionWeight.Get(stream) * w,
    31.                     targetRotationWeight.Get(stream) * w,
    32.                     hintWeight.Get(stream) * w,
    33.                     linkLengths,
    34.                     targetOffset
    35.                     );
    36.             }
    37.             else
    38.             {
    39.                 AnimationRuntimeUtils.PassThrough(stream, root);
    40.                 AnimationRuntimeUtils.PassThrough(stream, mid);
    41.                 AnimationRuntimeUtils.PassThrough(stream, tip);
    42.             }
    43.         }
    44. }
     
    twobob likes this.
  3. thebarryman

    thebarryman

    Joined:
    Nov 22, 2012
    Posts:
    130
    Is this the case for 2018.4 as well, or only 2019? For some reason I can't get an AnimationJob to Burst compile.
     
  4. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Caveat:To [BurstCompile] DO remember to include the refs in the asmdef
     
    Last edited: Oct 27, 2019