Problem with UI Button and Animation / Animator

Good Day,

I have made a UI button and attached the anchors to one corner of the canvas so when I have a different size screen it will maintain its general position (This works fine). Below are some pics of how it works for different size screens –

However, I am trying to add animation to the buttons using the Animator. So this is what I did in the inspector. Please note the animation were done as sequential sprites. This is how my INSPECTOR looked. I had to add Sprite Renderer to get the animation to show.

However this is what if looks like now when I used different screen sizes


Why doesn’t the sprite stay inside the Button Area? Shouldn’t the anomation be where the button is? Does anyone know to resolve this issue? I need the animation to stay inside the button area (the greyish square)
Thanks

You added a SpriteRenderer — at that point, it is no longer a button, it is a sprite. (Or rather, it is a button and a sprite.) These compute their on-screen positions in completely different ways.

You need to instead use an Image or RawImage object within the button in the scene hierarchy. You should be able to animate that with the Animator as well (Animator can update pretty much any public properties; in this case you’d be updating the .sprite property of the Image component).