• 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
9
Question by FeetSlashBirds · Mar 30, 2014 at 05:06 PM · 2danimatoranimator controlleranimationclip

Unity 2D : Can you change a 2D animation clip's sprites at runtime?

Hi there,

I'm working in Unity's 2D mode and using the Unity UI I've created a GameObject with an Animation Controller (Animator) linked up with six different Animation Clips. While running the game this GameObject properly transitions between all of the animation clips.

I'd like to use this object as a prefab. At runtime I want to clone it and swap out the sprites being used for the animation clip key frames.

In other words I have object A that uses a Sprite_Sheet_A. Now I want to clone Object A and start using Sprite_Sheet_B.

Once I clone object A how can I access its Animation Controller, view the Animation Clips being controlled and swap out their sprites?

EDIT: When I say Animation Clip... I might mean Animation. The difference between these classes in 2D is not super clear for me.

Comment
Add comment · Show 3
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 joshpsawyer · Mar 30, 2014 at 05:47 PM 0
Share

If you want to clone an object and change it's sprites at runtime, you'll need to do it with scripting. The relevant references can be found here, but it's likely that it won't be easy:

http://docs.unity3d.com/Documentation/ScriptReference/index.html

It's a better idea to make another prefab for the object with different sprites.

avatar image FeetSlashBirds · Mar 31, 2014 at 05:00 AM 0
Share

Thanks for the reply but I think you misunderstand my question. I am trying to clone a GameObject that has an Animator, Animator Controller and several Animation Clips attached to it.

Each Animation Clip is a series of sprites that add up to a frame-by-frame animation. I want to clone that and then replace each frame with sprites from a new sheet.

For example, lets say I have 2D game with a character that walks from left to right. I have animated the walking motion. Now I want to add a new character that reuses all of the animation logic. I don't want to remake ALL of the animations using a new set of sprites. I just want to copy the animation I made for the first character and apply the new sprites.

avatar image joshpsawyer · Mar 31, 2014 at 02:06 PM 0
Share

http://forum.unity3d.com/threads/213431-Changing-Animation-Sprites Unity says there's no easy way to do what you want in this thread, but supposedly Sprite$$anonymous$$anager can help:

http://wiki.unity3d.com/index.php?title=Sprite$$anonymous$$anager

8 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rinenproductions · Jan 09, 2020 at 03:33 PM

I had the exact same problem in my own project and I was able to solve it with an editor tool which works like this:

  1. Read the contents of a user-selected Animator Controller asset

  2. Read and store sprite-related keyframe data (original sprites, frame time) from the Animation Clips which are referenced inside the Animator Controller asset

  3. Find original spritesheet texture assets used in those keyframes

  4. Allow user to select the replacements for those original spritesheet texture assets

  5. Generate a Scriptable Object containing all sprite-related keyframe data with equivalent sprites from user-specified sources for each animation state along with the state hash

The generated Scriptable Object asset can then be used to override the sprites set by the Animator component during runtime by checking the current animation hash and picking out a replacement sprite from the Scriptable Object.

This way you are able to reuse the same Animator Clips and even the Animator Controller for any amount of animated objects which differ only in spritesheet sources.

You can find my solution to this problem here: https://assetstore.unity.com/packages/tools/animation/animator-sprite-swap-system-159842

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
0

Answer by Da_Elf · Oct 23, 2021 at 03:45 PM

What if i have an animated character as a sprite sheet (no bones) After game is launched i want to add new skins so i upload to the internet. The game will look for skins in the folder download them and save as a texture. What can i do from there? apparently i cant slice up that sprite sheet at run time nor can i swap the frames in the "idle down" or "walk left" animations. Are there any solutions for this? I dont want the user to keep having to download an update every time i create a new character skin.

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
0

Answer by Guambo1 · Dec 11, 2021 at 08:53 AM

So I made an unlit shader similar to the solution posted by @retry_entry. It doesn't require light in your scene. Check it out here (follow the README to make it work): https://github.com/NPVallejos/SwapSpriteSheetShader

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
  • ‹
  • 1
  • 2

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

36 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Why does my transition freeze the second animation on it's first frame? 1 Answer

How to move Animation Clips into Animator Controller? 1 Answer

Stop all animators 0 Answers

Animator Controller 2D RPG Best Practices 0 Answers


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