Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by seth_slax · May 31, 2016 at 01:12 AM · animationspriteswap

Animation and Sprite-Swapping

Hey everyone. I've combed through the forums and docs, and I've seen many questions similar, but I can't seem to find an efficient way to do this.

So basically, say I have an NPC with a whole heap of animations based on one sprite sheet. Is it possible to use the same animation clips/controller with a different set of sprites?

So far I've uncovered two methods of doing this:

  • Replace all sprites in the SpriteRenderer component using Resources.Load in LateUpdate() with sprites of the same name. (Courtesy of Unity lectures video).

  • Use Animation Events to reassign sprites manually through script.

Both of these methods work fine, but the first is very resource-heavy, especially in multiple instances, and the second requires a lot of code on my part (since there will be 50+ animations per NPC), or a large sprite array, which again will be resource-heavy with several instances. Are there any alternate methods to achieve this, preferably without a lot of overhead?

Also, does anyone know if Unity plans to integrate something like this any time soon? Some of the forum posts are from back in 2010.

Comment
Add comment
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 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rinenproductions · Jan 08, 2020 at 06:45 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

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

95 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 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 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

SpriteRenderer animation generics? 0 Answers

How can I animate a sprite sheet in Java 1 Answer

Rotate a Sprite Without Using Its Pivot Or Parent GameObject 1 Answer

Customizable characters with sprites in 2d 0 Answers

2D Sprite animation - How do I jump to the next frame? 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