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

Check if IK pass is enabled at runtime

Discussion in 'Animation' started by Baste, Nov 23, 2017.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    I'm assuming this isn't possible, but I thought I'd check;

    Is there any way to check if the animator controller on an Animator has IK passes turned on in any layers? I want to output error messages from my animation setup if IK methods gets called when they're not supported, but that means that I need to be able to check that somehow.

    Animatior.SetIKHintPosition just silently does nothing if it's called on an Animator which doesn't have any passes.
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Unfortunately there is no function to check this directly at runtime.
    I will add a feature request for this.

    As a workaround you could create a debugging MonoBehaviour on your GO and define the method
    https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnAnimatorIK.html
    And enable the monobehaviour only when you need the debugging info.

    It's not the most beautiful workaround but should at least allow you to debug
     
    theANMATOR2b likes this.
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    I'd like to be able to output errors already in Awake, in case somebody wants to set IK targets already there.

    My solution will simply be to have "Support IK" be a checkbox in my tools, and then (at edit time) check if there's any IK availalbe and show an error message in the inspector if not.


    I'm doing all my animations through Playables right now. The reason for needing to check for IK passes in an AnimatorController is because I haven't found any way to do IK purely in Playables yet. From what I've seen in the blog, it looks like there will be some kind of playable/job solution to IK in the future, so I guess it's safe to assume that need for an AnimatorController is temporary?
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Ah so if you do it in the Editor you can use the editor class to get this information
    You can find it in the animation controller layer
    https://docs.unity3d.com/ScriptReference/Animations.AnimatorController-layers.html
    https://docs.unity3d.com/ScriptReference/Animations.AnimatorControllerLayer-iKPass.html

    Effectively, i'm working right now on animation jobs which will give you access to all the internal animation data(transform matrix, muscle value, float values, int values, IK).
     
  5. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
    Why isn't it possible to read and write that flag at runtime?
     
    Last edited: Jul 7, 2018