Search Unity

Other Animator component doesn't change SpriteRenderer value at runtime

Discussion in 'Animation' started by BetterLife_R, Dec 12, 2022.

  1. BetterLife_R

    BetterLife_R

    Joined:
    Nov 16, 2021
    Posts:
    19
    I have an Animator component that has a few different animations which change the sprite of the object it's attached to. The sprite does change in the game scene, however whenever I access the SpriteRenderer in my C# script the sprite is always set to the default sprite that it starts with.

    For example let's say I have some character sprite and a run animation. When I play the run animation, during each Update loop I get the the current sprite from the SpriteRenderer but it's not set to any individual frame from the run animation, instead it's the normal character sprite.

    My question is how do I find out what sprite is being shown when an animation is playing?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You must be checking the wrong SpriteRenderer. Sprite animations literally just set the sprite on the renderer so if it wasn't getting set then you would not see the animation playing.
     
  3. BetterLife_R

    BetterLife_R

    Joined:
    Nov 16, 2021
    Posts:
    19
    Well that's what I thought, but I only have one SpriteRenderer that I'm checking on the object. I didn't think you could have more than one sprite renderer on a single game object