Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Stop animator from playing, return to sprite renderer.

Discussion in 'Animation' started by MachineHead, Jul 6, 2021.

  1. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
    I'm using Sprite Renderer when I have my character move left and right. It cycles through two single frame sprites. Does it just fine. However, I have another input that activates the animator to play a sprite animation through the Animator. player.play("player");

    I can't get it to stop. player.stop("player"); doesn't work. rebind, stops it, but it doesn't revert it back to the sprite renderer, so the two single frame sprite frames I have cycling through, don't render. I'm sure its because I'm going through both sprite renderer and animator, but thats what I need, because the player doesn't have a heavy amount of animations. So I'm hard coding it when it plays.

    How to I stop the Animator from playing, and revert back to the idle state of the Sprite Renderer?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,873
    Setting the animator.enabled = false should stop it, but I'm not sure if it would revert back to the previously assigned sprite.

    You might also be interested in Animancer (link in my signature) which lets you play animations directly in your scripts without needing an Animator Controller. If you're only using sprite animations then you likely don't need any of the Pro-Only features so you can use Animancer Lite for free.
     
  3. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
    Its free, I'll give it a try.
    In the mean time. I have to bite the bullet and make my single frame sprites into single frame animations to activate in the animator. Left-Right and Idle, so the animator can go back to the start animation. I should still be able to hard code the plays, and since the plays never stop, it will play idle infinitely.
     
  4. KalOBrien

    KalOBrien

    Unity Technologies

    Joined:
    Apr 20, 2021
    Posts:
    88
    It might be better workflow to use just the animator instead of switching sprites via the sprite renderer itself. Any reason as to why you're doing it this way particularly?
     
  5. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
    I understand hard coding it more than using the animator at the moment.
    I'm still very much a beginner and going off what I know, not whats best.
     
unityunity