Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cannot set Sprite in SpriteRenderer from Code when SpriterRenderer may be animated

Discussion in 'Animation' started by talecrafter, Mar 4, 2014.

  1. talecrafter

    talecrafter

    Joined:
    Mar 26, 2013
    Posts:
    34
    I have an Object with an Animator Component. Some child element is a SpriteRenderer and in one of the Animator states the sprite gets switched. But even though that state is not triggered, I cannot set the sprite from code.
    Even if I call spriterRenderer.sprite = otherSprite at every Update() it doesn't work. But if I call it at LateUpdate(), it works. So I assume some code from the animation system get's called between Update and LateUpdate.
    And if I delete the sprite change property from the animation, the code also works.
    Again, I repeat, the state with the animation containing the sprite change property is not even called.

    Is this a bug or expected behaviour? (e.g, "Don't mess with sprites that may be manipulated by Mecanim, even though they are not actually manipulated!"