Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Jan_Julius · Jul 15, 2015 at 12:55 PM · uispritespritesheet

Load specific sprite from sprite sheet

I have a sprite sheet with multiple sprites, how can I load a sprite into my game from my resource folder?

I have this:

 type2sprite = Resources.Load<Sprite>(
                     Settings.typeSpritePath + Settings.getType2(party[i].pokedexNumber).ToString()) as Sprite; 


The getType2 will return a type for example "GRASS", and I have a sprite in my sprite sheet called GRASS, how can I take that sprite from my sprite sheet?

Comment
Add comment · Show 2
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 zedseven · Jul 15, 2015 at 12:58 PM 0
Share

What do you mean by sprite sheet? Is it an image with individual tiles for sprites, or an image that you split up in the Sprite Editor? I'm not quite sure what you mean.

avatar image Jan_Julius · Jul 15, 2015 at 01:25 PM 0
Share

http://gyazo.com/1beaea0845bc4860e1f170164da798d2

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by dazzle_wolf · Nov 20, 2015 at 06:19 PM

@Jan_Julius As far as I know, you can't.

I need to do the same thing and I have a workaround for it: You could replace the sprite using its pivot and rectangle. Basically, you would move the UV coordinates used for the sprite rendering to use a different part of the atlas. The problem is that Unity does not allow you to access the texture, pivot or rectangle of a sprite (they are read-only).

So this is how you do it: When packing the sprites into the atlas, I generate a .txt file with the sprite's name, pivot and rect. Then at the start of the game, I load the atlas and the .txt into my UIRepository-class. To switch out a sprite for one in this atlas, you can now get the sprite's pivot and rect using its name. However, the only way to actually do this is to create a new sprite with these attributes at runtime (again, since its read-only). This is really, really slow, though. To lessen the impact of this, I cache the sprites but there is still a huge cost the first time you need it.

If you find a better way of doing this, please let me know :-)

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

23 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

Related Questions

Turning GIFs to spritesheets IN UNITY 1 Answer

Change entire spriteSheet from animation tree 2 Answers

[2D graphical bug] Sprite Edge blends. Why this is happening? 1 Answer

How do I size a UI Image to fit the sprite exactly? 2 Answers

Interface relative scaling 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