Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
16
Question by Whelandrew · Mar 24, 2015 at 07:31 PM · uiimagespritesheetanimate

Animate Image UI with Sprite Sheet

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bobbyjoe6128 · Nov 11, 2015 at 12:59 AM 0
Share

Thanks for your clear answer :)

3 Replies

· Add your reply
  • Sort: 
avatar image
56
Best Answer

Answer by DiegoSLTS · Mar 24, 2015 at 08:42 PM

You can animate the Image.sprite property of your UI Image with an animation.

  1. Select your Image in the hierarchy

  2. Open the Animation window

  3. Press the "Add property" button

  4. Save the animation clip with anything you want

  5. Add the Image.sprite property

  6. 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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zafadadynamic · Jul 06, 2015 at 10:01 AM 5
Share

Don't forget that you can drag and drop multiple sprites in the animation window at a time.

avatar image CNachtrieb · Jul 08, 2015 at 05:31 PM 1
Share

But how would you do this through script, allowing a designer to just plug in an sliced sprite sheet with different numbers of columns and rows? Wouldn't using the animator component lock you into using only the selected sprites?

avatar image DiegoSLTS · Jul 08, 2015 at 06:31 PM 0
Share

@CNachtrieb, that's really different, you should ask a new question, but you can load a texture from resources, get the size of ths sprites, create new sprites from each section and then switch them with code at the speed you want. $$anonymous$$aybe you can also create an animation clip at runtime, but I'm not sure about that.

avatar image earthcrosser · Jul 15, 2015 at 02:11 PM 0
Share

This answer helped me thanks!

avatar image drewjosh · Nov 24, 2020 at 10:11 PM 0
Share

Top! This worked perfectly! Drag and drop the sprite slices from the sprite sheet did the magic!

Show more comments
avatar image
3

Answer by AQaddora2020 · Oct 06, 2020 at 10:13 AM

Hey there! I know this is old, but here is a script I have worked on that achieves what you want.

 using UnityEngine;
 using UnityEngine.UI;
 
 [RequireComponent(typeof(Image))]
 public class UISpritesAnimation : MonoBehaviour
 {
     public float duration;
 
     [SerializeField] private Sprite[] sprites;
     
     private Image image;
     private int index = 0;
     private float timer = 0;
 
     void Start()
     {
         image = GetComponent<Image>();
     }
     private void Update()
     {
         if((timer+=Time.deltaTime) >= (duration / sprites.Length))
         {
             timer = 0;
             image.sprite = sprites[index];
             index = (index + 1) % sprites.Length;
         }
     }
 }
   


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Hendryx · May 04, 2020 at 09:08 AM

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.

  1. Drag the multiple sliced frames into the scene view and make a new animation, name it something that makes sense

  2. Make sure the new gameobject has an image component

  3. Drag the first frame of your animation into the image component "source image" box

  4. Have one of the states in your animator use your newly created animation as its "motion"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you animate the material of a Canvas Image? 0 Answers

RenderTexture does not render canvas image. 0 Answers

UI Escape menu script not working. 2 Answers

Image on game object is not being rendered 1 Answer

How do you automatically fit a child of a layout group to the parent without it adjusting to fit its own contents? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges