Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
avatar image
0
Question by KazenoZ · Jul 28, 2017 at 03:21 PM · animationanimatoranimator controllerspritesheetdesign-patterns

Single Animator for multiple similar sprite sheets

Hey guys,

I have an interesting question that probably has a simple answer I'm not aware of at this point, so any assistance from people more knowledgeable on this subject would be great =)

I'm working on a 2D game that has a character, represented by a UI.Image, with multiple skins (Different colorations of the exact same animations in this case). Now, since it's a sprite, to animate this character I basically made an Animator that controls animations that change the active sprite of the character. The problem is that due to sprite changes being recorded as part of the animation, that means I need to create a separate Animator and animations for each character that are exactly the same and only use each skin's equivalent sprite on each keyframe.

Given that my 2 skins have exactly the same number of frames which are exactly the same in poses on each frame and only differ in minor details, I'm looking for a solution that will let me use a single Animator that I can feed a sprite sheet to as an input parameter and the Animator will just tell the image which sprite in the spritesheet it should use on each keyframe.

Something like a Strategy Design Pattern but for animations, if that makes sense.

Is anyone aware of such a solution or do I need to write this on my own?

Thanks a lot~

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 KazenoZ · Jul 28, 2017 at 03:30 PM 0
Share

Note, I had in $$anonymous$$d the same solution suggested in this post: https://forum.unity3d.com/threads/different-sprites-with-the-same-animation.410769/

However, I'm looking for a solution that's more elegant to our content creators, and was generally wondering if a tool exists for this job already.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KazenoZ · Jul 28, 2017 at 11:38 PM

I ended up going with a solution similar to this one: https://forum.unity3d.com/threads/different-sprites-with-the-same-animation.410769/

Except I separated the functionality to 2 classes

 public class AnimationDispatcher : MonoBehaviour
 {
     public void SetSpriteId(int i_SpriteId)
     {
         foreach (AnimationHandler handler in GetComponentsInChildren<AnimationHandler>())
         {
             handler.SetSpriteId(i_SpriteId);
         }
     }
 }

And

 public class AnimationHandler : MonoBehaviour
 {
     [SerializeField]
     private string m_SpriteSheetPath;
 
     private Sprite[] m_Sprites;
 
     private Image m_CurrentSprite;
 
     // Use this for initialization
     private void Awake()
     {
         m_Sprites = Resources.LoadAll<Sprite>(i_SpriteSheetPath);
         m_CurrentSprite = GetComponent<Image>();
 
         m_CurrentSprite.sprite = m_Sprites[0];
     }
 
     public void SetSpriteId(int i_SpriteId)
     {
         m_CurrentSprite.sprite = m_Sprites[i_SpriteId];
     }
 }


Where AnimationDispatcher is placed on the animated object and the SetSpriteId is called by the Animation Event, and AnimationHandler is placed on the specific skins childed to the object holding the AnimationDispatcher. This allows me to forward the sprite change request to the specific active skin.

Note that my skins dynamically change during the game, making it impossible to gather a list of AnimationHandlers in the Awake method of the script, but normally it's a good idea to populate that list once instead of poll for it this often, as it's a performance-problematic call.

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

172 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

Related Questions

What are the best practices for reusing an animation controller? 0 Answers

2DAnimator Freezes first time an animation is played 0 Answers

Animator Controller 2D RPG Best Practices 0 Answers

Animtion looping if joystick is held 0 Answers

Is there a new retargetting system for the animation in 5.5? 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