Search Unity

Can Mecanim Animation-Clip properties be edited in script?

Discussion in 'Animation' started by JOHNMCLAY, Jun 15, 2014.

  1. JOHNMCLAY

    JOHNMCLAY

    Joined:
    May 23, 2012
    Posts:
    38
    Properties like:

    - Loop Time
    - Loop Pose
    -
    - Offset - Bolded because: Typically the root-rotation of animations alters the GameObject's transform.rotation undesirably, which causes some awful & mismatched transitions.

    Usually this happens between animations that have 'root motion baked into the pose' and those without.

    Can these variable be exposed and controlled by script, or curves or something?

    Essentially to alter just the root-rotation!

    Thanks for your time :)
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi john,

    You cannot edit or control these properties at runtime, these values can only be changed in the editor.

    The only way to control the root motion at runtime is through MonoBehavior.OnAnimatorMove message.
     
  3. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    I want to do the simplest thing. Create an animation clip procedurally, save it to the assets and use it with Mecanim. I can't, because I can't change the AnimationClipSettings. I cant change the loop time, stop time or any other variable.
    I know I can manually change them in debug mode, but that is not a solution, I need to do it programmatically.

    Best Regards,
    Pärtel
     
    PrimalCoder and mhtraylor like this.
  4. JOHNMCLAY

    JOHNMCLAY

    Joined:
    May 23, 2012
    Posts:
    38
    Hey Mecanim.Dev,

    Thanks for the info.! However, I found if I just utilised 4.5's Root-Motion node option and created my own custom root-motion node/rotations in Maya then I get exactly what I'm looking for!

    What a powerful feature. I'm constantly salivating over how robust mecanim can be!

    If you have the time, I'm curious about how the Entry/Exit nodes in Unity 5 will work? Do they have special functionality or do they help to keep more comprehensive state-machines visually cleaner, or both? Do they function similar to the 'Any State' transitions?

    They look good either way...your team's doing amazing work! :)
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Ah this is another thing, I thought you would like to change all these settings at runtime. Yes you can edit these properties in the editor with a script. You can do it with SerializedObject and SerializedProperty.

    Take a look at attached script

    Best regards,
     

    Attached Files:

    mhtraylor likes this.
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Yes they do have a special functionnality and also keep the statemachine visually cleaner because they offer a way to connect state machine to state machine directly which abstract detail from the state machine. Each entry node can define a serie of transition with condition that allow you to determine to which state it should transition. To some extend they work like an Any state but restricted to state in this state machine.

    Keep an eye open on the blog section, we should post something related to state machine transition in the upcoming week.
    http://blogs.unity3d.com/
     
    TMPxyz and JOHNMCLAY like this.
  7. JOHNMCLAY

    JOHNMCLAY

    Joined:
    May 23, 2012
    Posts:
    38
    Sounds great! Thank-you for the information and I'll keep an eye on the blog! :D
     
  8. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Thats excellent, big thanks for the script!

    Cheers,
    Pärtel
     
  9. Verdo

    Verdo

    Joined:
    Jul 23, 2015
    Posts:
    9
    Hey there, sorry for the bump but i was wondering if you could help me figure out how to actually use this script to apply it to what im doing...as im still fairly new to unity and this still confuses me. I have a method where im trying to switch from one animation (that is looping) to another. My issue is that every time i try to switch the animation by reseting its trigger, it still continues to loop the animation instead of switching back to my default Idle animation. If i implement the code you posted into my script, what code would i have to enter into this method in order to turn the loop time off of my walking animation which is turned on by my WalkOn trigger?

    public void StopWalkingAnim() {

    Player = GameObject.Find("0");

    animationsB = Player.GetComponent<Animator>();

    animationsB.ResetTrigger("WalkOn");
    animationsB.SetTrigger("WalkOff");

    }

    Anyone who can help, i'd greatly appreciate it
     
  10. ShaunSun

    ShaunSun

    Joined:
    Jun 14, 2016
    Posts:
    1
    hi.
    I am a Chinese,my english is not very good,I am sorry about that >.<.

    I download and run your script in Unity5.3.4f1.

    The Unity tell me "The type `UnityEditor.AnimationClipSettings' does not contain a constructor that takes `1' arguments"

    thanks for your time.