Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Will Mecanim Api allow me to automateThresholds and motion speeds from script?

Discussion in 'Animation' started by TheSin, May 26, 2015.

  1. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    As the topic says, I need to be able to build my own controller using my own automated system without then having to do things by hand in mecanim ie setup thresholds and set speeds of motions contained in a blendtree etc
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  3. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    From playing with those, i'm unable to set individual motion speeds in blendtrees. Regarding thresholds, nothing happens as automateThresholds cant be changed through scripting.

    Am I just missing something? Example please?

    BlendTree children have no speed field I can access and change.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    To set the speed of each motion you need to use
    http://docs.unity3d.com/ScriptReference/Animations.ChildMotion-timeScale.html

    As for thresholds, you are absolutely right. We will fix this but meanwhile you can use serializedobject to set this value to false.
    Code (CSharp):
    1.  
    2. BlendTree myBlendTree;
    3.  
    4. SerializedObject serializedObject = new SerializedObject(myBlendTree);
    5. m_UseAutomaticThresholds = serializedObject.FindProperty("m_UseAutomaticThresholds");
    6. m_UseAutomaticThresholds.boolValue = false;
    7. serializedObject.ApplyModifiedProperties();
    8.  
     
  5. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    Thanks for the reply. Still issues as :

    bt.children.timeScale
    bt.children.threshold
    bt.children.mirror

    These have no affect on the default settings. Im looping through and changing them, nothing changes on them.
    The hack above works to change the automateThresholds but then it's useless as i'm still required by hand to changed the rest.
     
  6. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    It's definately broken. I can set variables from reading those fields but cannot apply any changes to the fields :-(
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    theANMATOR2b likes this.
  8. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    Haha thanks again. Things are becoming clearer now.
     
  9. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    Massive thanks, works perfectly and now I can automate a controller from my system.
     
    theANMATOR2b and Mecanim-Dev like this.