I’ve been digging around for a while but don’t seem to be able to find a solution. Does Unity support this option? Seems like something that should be possible.
The method for making a basic 2D animating sprite does not show up in the UI when I attach it to a panel. I have also created an Image object and added an animator to it with no effect.
What am I missing?
You can animate the Image.sprite property of your UI Image with an animation.
- Select your Image in the hierarchy
- Open the Animation window
- Press the “Add property” button
- Save the animation clip with anything you want
- Add the Image.sprite property
- Add keyframes with the different sprites you want
This will automatically add an Animator component with everything configured to play that animation in an infinite loop.
I know this is old, but here is a script I have worked on that achieves what you want.
public class UISpritesAnimation : MonoBehaviour
public float duration;
[SerializeField] private Sprite sprites;
private Image image;
private int index = 0;
private float timer = 0;
image = GetComponent<Image>();
private void Update()
if((timer+=Time.deltaTime) >= (duration / sprites.Length))
timer = 0;
image.sprite = sprites[index];
index = (index + 1) % sprites.Length;
For anyone else struggling, I had to make sure that I had a gameobject in my scene with an image component and to add a frame of my anim to it - to make it work:
The object you add to the scene doesnt need to be visible, you can just use the animator component of an object in your scene to switch between states but for some reason, the objects need to exist in the scene.
- Drag the multiple sliced frames into the scene view and make a new animation, name it something that makes sense
- Make sure the new gameobject has an image component
- Drag the first frame of your animation into the image component “source image” box
- Have one of the states in your animator use your newly created animation as its “motion”