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
0
Question by jakejolli · Jul 08, 2016 at 12:37 AM · 2dspritespritesheet

Change Spritesheet Programatically

Can an animation's sprite sheet be changed programatically? I know that I can use mecanim to define different animation states and set bools/triggers, etc. etc., but that's not what I mean.

I have an enemy that uses sprite sheet animation. He has the ability to lose limbs, so I have sprite sheets for each permutation of lost limbs (no left arm, no right arm, no arms, no head and no left arm, no head and no right arm, etc.), and color variations of each of those permutations. In total, I have like 20 sprite sheets for this one enemy, and I really don't feel like defining a separate animation state for each. I can do it if I have to, but I was hoping I could do something like this (pseudocode) to save some time:

 public SpriteSheet allLimbs;
 public SpriteSheet noLeftArm;
 public SpriteSheet noLeftArmNoHead;
 public SpriteSheet noArmsNoHead;
 ...
 public enum Limb{
    Head, LeftArm, RightArm
 }
 
 public void LoseLimb(Limb limb){
    if(limb == Limb.Head){
       SwitchSpriteSheet();
       ...
    } ...
    ...
 }

Can this sort of thing be done natively in Unity? If not, it's probably quicker just to do the individual animation states for my purposes, rather than write a custom SpriteSheet class and parse image data.

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 Cherno · Jul 08, 2016 at 01:04 AM 0
Share

Just a note,, in case it's not possible (I really hope it is though, since I ned it for my project as well): Consider using a shader that supports palettes, this way you can assign different palettes based on the damage your character receives (use transparent colors for holes in the body). Of course, the spritesheet bitmap has to be set up the right way so that each possible damage area has it's own color.

avatar image tanoshimi · Jul 08, 2016 at 05:51 AM 0
Share

What is the SpriteSheet class you're using? Unity's own Sprite atlas, or a third party such as Texture packer? If your sprites are always arranged in the same layout on each sheet, is it not just a case of changing the renderer.shared$$anonymous$$aterial.mainTexture to the appropriate sheet?

avatar image jakejolli · Jul 08, 2016 at 11:43 AM 0
Share

@tanoshimi That's just pseudocode. I don't actually have a SpriteSheet class. That's just something like what I was hoping to accomplish. I'm using all stock Unity stuff in my project, and using frame animation from the spritesheet using animations in mecanim. All of my spritesheets are exactly the same in dimensions and number of frames. I'll look into the solution you've mentioned, but I have a feeling the animation will overwrite any sprites/textures I assign through code. I suspect I'll have to access the Animator in order to achieve what I'm looking for.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mikest · Jul 09, 2016 at 07:34 AM

this is a pretty typical 2D scenario. There is a trick to do what you want. If you watch this video starting at about 19:20 you can see the basic idea for how to do sprite swaps.

https://www.youtube.com/watch?v=rMCLWt1DuqI

I do something similar in my games, but rather than naming the sprites as in the video, I slice them and make sure that i am always referencing the same frame. I did a blog post on it but it's not very detailed but it might give you some ideas on how to approach the problem in your game.

http://blog.hofstudios.com/post/140743627622/cubicle-run-devlog-art-and-animations

Hopefully i have understood your issue.

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

83 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

Related Questions

Sprite Shape not working (need help/suggestions!) 2 Answers

Sprites in spritesheet have strange edges in the sprite editor but not in art software 2 Answers

how do I change a 2D Sprite Character Image/Graphic to another Sprite Character Image/Graphic with the same movements, animation,mechanim etc. 2 Answers

Sprites with Mipmaps Vibration Effect on Animations Problem 0 Answers

Fast Sprites Extraction from Sprite Sheet 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