Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Animation playable output sorting order

Discussion in 'Animation Previews' started by danUnity, Jul 28, 2020.

  1. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    66
    Hi,

    I know we can set the animation playable outputs sorting order in order to make sure that the Rigbuilder outputs be executed after the Animator's own outputs but I'm not 100% how.

    This is what I have so far:

    Code (CSharp):
    1.  
    2. RigBuilder rigBuilder = GetComponent<RigBuilder>();
    3. for (int i = 0; i < rigBuilder.graph.GetOutputCount(); i++) {
    4.     AnimationPlayableOutputExtensions.SetSortingOrder((AnimationPlayableOutput)rigBuilder.graph.GetOutputByType<AnimationPlayableOutput>(i), 5);
    5. }
    I'm also not sure what sorting index to use... So far I haven't seen any changes when using the previous code.

    Thanks!
     
  2. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    158
    You could rewrite your bit of code like this:
    Code (CSharp):
    1.  
    2. RigBuilder rigBuilder = GetComponent<RigBuilder>();
    3. for (int i = 0; i < rigBuilder.graph.GetOutputCount(); i++) {
    4.   ((AnimationPlayableOutput)rigBuilder.graph.GetOutput(i)).SetSortingOrder(5);
    5. }
    `AnimationPlayableOutputExtensions.SetSortingOrder` is an extension method, so the first parameter is prefixed with `this`. This is unfortunately not well highlighted in the documentation.

    Otherwise, AnimationRigging already sets the sorting order for all outputs on the RigBuilder PlayableGraph, so you shouldn't have to set it yourself.

    The Animator state machine always takes precedence over all other outputs. Otherwise, the default sorting order for outputs is set to `100`, while AnimationRigging sets it to `1000` for each of its output.

    The default sorting order index is mentioned here:
    https://docs.unity3d.com/2019.4/Doc...PlayableOutputExtensions.GetSortingOrder.html

    Cheers!
     
    danUnity likes this.
  3. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    66
    Ah ok sounds good! Didn't realize they were actual extensions methods and not just some utility methods... Makes more sense now!

    Thanks for the clarification! The sorting order is definitely a subject that lacks some documentation but your explanation is very clear, thank you!
     
unityunity