Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
3
Question by Awks_Beans · Sep 06, 2017 at 07:00 PM · animationtexturespritespriterendererspritesheet

Same animation from multiple spritesheets

Okay, let's say I have a 2D character that uses a bunch of different animations (walking, jumping, idle) in an animation controller - all dragged out of a spritesheet.

He's currently in his undies, and needs some layers. I've created an identical sprite sheet with just the clothes layer and made sure the frames relate to the original sprite sheet.

Is there a more simple way for me to create a layer on top of the character, that performs the same animation transitions - just from a different sprite sheet?

I could set up animations and animation controllers for every item of clothing, but if I'm separating out legs/bodies/hair/eyes - that's a lot of animations that all basically do identical things, just on a different spritesheet.

Thanks!

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 schwollie · Sep 05, 2019 at 12:21 PM

Well, I personally don't like this solution, but you could put your SpriteSheets into the Resources Folder and than load them by this script:

 using UnityEngine;
 using System;
 
 public class ReSkinAnimation : MonoBehaviour
 {
 
     public string spriteSheetName;
     void LateUpdate()
     {
         var subSprites = Resources.LoadAll<Sprite>("PlayerSpriteSheets/" + spriteSheetName);
         print(subSprites.Length);
 
         foreach (var renderer in GetComponentsInChildren<SpriteRenderer>()) {
             string spriteName = renderer.sprite.name;
             var newSprite = Array.Find(subSprites, item => item.name == spriteName);
             if (newSprite) { renderer.sprite = newSprite;}
         }
 
     }
 }


But you have name each sprite exactly the same as in the default spriteSheet...

Here is the video where I have found that solution

So I have edited this script so that you don't have to rename all your Sprites:

 using UnityEngine;
 using System;
 
 public class ReSkinAnimation : MonoBehaviour
 {   
     [Tooltip("This is the standard SpriteSheet where the script gets its indexes from.")]
     public string defaultSpriteSheetName;
     public string spriteSheetName;
 
     Sprite[] subSprites;
     Sprite[] defaultSubSprites;
 
     private void Start()
     {
         subSprites = Resources.LoadAll<Sprite>("Player/PlayerSpriteSheets/" + spriteSheetName);
         defaultSubSprites = Resources.LoadAll<Sprite>("Player/PlayerSpriteSheets/" + defaultSpriteSheetName);
     }
     void LateUpdate()
     {
         foreach (var renderer in GetComponentsInChildren<SpriteRenderer>()) {
             int spriteIndex = Array.IndexOf(defaultSubSprites, renderer.sprite);
             var newSprite = subSprites[spriteIndex];
             if (newSprite) { renderer.sprite = newSprite;}
         }
 
     }
 }


Hopefully they will add a nicer solution for this problem soon...

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

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

Big sprite textures with animations appears distorted and flickers, only in build. 2 Answers

Cannot add Texture to Tile Palette when Sprite Mode is Multiple 1 Answer

Use a Sprite Background multiple times or plane with texture repeating? 0 Answers

Changing sprite and animation, through script 1 Answer

Animation Sprite on infinite particle 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