Hello everyone,
I have an animator attached to my player with currently 4 states. Three animations change the Sprite and one of these animations has “no motion” because my idling “animation” is a single Sprite : the Sprite attached to the object at the beginning. I have noticed that in Unity the Animator saves the “default” values on it for when there is no animation.
Now, I want to change this Sprite from code during the idling state (without motion). One solution is to create another animtion but as it is only one sprite, I think it is a bad idea. I don’t know if it is possible, but I want to override the “default” values saved on the Animator (the values, used on the WriteDefaultValues method).
Thanks in advance for your answer
AFAIK you can change this as long as you untick that Write Defaults checkbox for the states where you don’t want that value changed. Pretty sure that would “just work,” and then when the animator moves onto an animation that DOES set that sprite, it will revert to what the animation says.
Are you saying you want a different custom set of changed-out sprites? That might need you to either remove all setting of the sprite via the animator and just put the sprite in with code, perhaps by observing StateMachineBehaviour changes? Not sure what your exact use case is.
Thanks to your answer. In fact my player have 2 states: on foot or a bike. I currently have 6 different animations (3 directions * the 2 states) that change the sprite of my player. In addition, I have 2 Sprites representing the idle states. To avoid repetition, my Animator contains 4 states : the 3 directions and the idle state.
As the idle state is not an animation but a single sprite, the state doesn’t contain any motion and with the “Write default”, the Sprite become the default (as I want because it is the idle on foot).
When I want to got on a bike, I override the animator with an AnimatorOverrideController (for change the move animations) but I can’t replace the idling state (because there is no motion). Changing the Sprite in code doesn’t work because the default Sprite is not on a bike.
I don’t know if it is possible, but I want to change the “default” Sprite value on the Animator.
I know that it is possible to create a new animation in order to override it and thus get around the problem, but since it is a single sprite and not animated, I wonder if it is really good to create an animation.
Why not? If the solution is to reach orthogonality by completing your dataset, it’s only gonna be a few bytes of data!