Search Unity

Question Stop an animation property from playing?

Discussion in 'Animation' started by PersianKiller, Mar 24, 2023.

  1. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    132
    Is this possible to stop for example B property from playing when the animation is playing?
     

    Attached Files:

    • uf.png
      uf.png
      File size:
      31.1 KB
      Views:
      74
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    I found a way to do this at runtime, but it's a little janky.

    Basically, if you want a property to stop playing, change the name of the object for that property so that the reference is broken, then call
    Animator.Rebind()
    so the Animator actually recognizes the change. This will stop that property from playing. To make it work again, change its name back and call
    Animator.Rebind()
    again.

    This method will break all references to that object, so if you want to stop an object's position change, but keep a rotation change, unfortunately this won't work for that.
     
    Last edited: Mar 28, 2023
    PersianKiller likes this.
  3. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    132
    Now I'm using animation event ,so I can manage it inside script ,btw thanks :)
     
    Unrighteouss likes this.
  4. NuclearApples

    NuclearApples

    Joined:
    Apr 3, 2020
    Posts:
    5
    There is a somewhat of a dirty approach but works without fail.

    if you add an empty anim to your animator and give no transitions to it but have a transition from empty to whatever the next anim you want is and change the transition times to 0 so it’s forced quit whatever is playing and just go straight to the one you want.

    you can call the empty state by calling a

    animator.Play(“EmpyAnimName”);

    will play the empty without fail then translation to the one you want.
     
    PersianKiller likes this.