Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Languard · Jan 01, 2014 at 09:03 PM · 2d2d spritespixelworld space

Need help understanding how Unity sizes sprites in world space

Setup: I have a 64x64 pixel png. I've triple checked this, it is indeed a 64x64 image. In the game window, I set a custom fixed resolution of 640x480. I create a sprite from the Game Objects menu, and reset the transform so that it's at 0,0,0. The camera is left with the default size of 5.

Now logically speaking, if I set the x scale of the sprite to 10, it should take up 640 pixels, or 100% of the width. This is not the case. Instead I have to set the scale to 20.8, and even then I can still see a tiny sliver of blue on the edge.

So, the question: How do I figure out what the pixel-to-world space conversion is? What magic is Unity doing behind the scenes to require a 20+ scale to get 64 pixel sprite to cover 640 pixels?

The end goal of this knowledge is to determine at run-time how large various sprites need to be at various screen resolutions.


EDIT: Additional information: Pixels to Units has not been changed from the default, it is still 100. I took a screen shot of the game window, and the pixels on screen was 31.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by HappyMoo · Jan 01, 2014 at 11:17 PM

Ok.. let's see if we can figure this out...

You created a sprite. By default the PixelToUnits=100 and you didn't mention it, so you probably didn't change that. Which means that the sprite is 64/100 = 0.64 x 0.64 units(m) in size.

Now, the cam.orthographicSize=5 is half the vertical size of the viewing volume, which means your 640x480 pixels viewport is (10*640/480=) 13.333 x 10 units in size.

So if your viewport is 13.333 units wide and your sprite is 0.64, you need to scale it to 10.333/0.64 = 16.146 ...

... which is not the number you got ...

Now, this suggests you actually DID change the PixelToUnits value and seeing the numbers, you probably thought it's a good idea to put this value to PixelToUnits=128 (hopefully)

which would mean that your sprite was actually 64/128 = 0.5x0.5 units in size.

The viewport sizes are the same and your scale value would have to be....

drum roll

10.333 / 0.5 = 20.666

Now we can surely ignore that you actually said the scale was 20.8+, because that would mean you put the PixelToUnits to something arbitrary like 129 .... and no one is THAT evil...

Comment
Add comment · Show 5 · 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
avatar image Languard · Jan 01, 2014 at 11:29 PM 0
Share

PixelToUnits? Never heard of it till now :) Just checked my importer settings and it's still set to 100. That does give an additional avenue of exploration though.

avatar image HappyMoo · Jan 01, 2014 at 11:44 PM 0
Share

do you have any scales anywhere, or are you sure you set the game view to 640x480, because it works perfectly for me.

avatar image Languard · Jan 02, 2014 at 12:01 AM 0
Share

If I alter the pixels to units to 64 so its 1:1 then I can apply a scale of 13.333 and it will fill 100% width.

avatar image HappyMoo · Jan 02, 2014 at 12:06 AM 0
Share

Other values should behave the same according to the above formulas - don't they?

avatar image HappyMoo · Jan 03, 2014 at 10:48 PM 0
Share

did that help?

avatar image
0

Answer by Wallyy · Feb 12, 2020 at 02:51 AM

I think the Size property of the camera is half of it's actual height.

I set a scene with the following:

.

  • Pixels Per Unit: 100 (default)

  • game view resolution: 1000x1000

  • camera Size: 5 (default)

  • example sprite resolution: 1000x1000 pixels

  • example sprite Pixels Per Unit: 100 (default)

.

1 pixel = 0.01 units

0.01 x 1000 = 10 (units)

.

The sprite fills 100% of the camera viewport.

Camera height (and width in this case) is 10 (Size 5).

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

22 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

Related Questions

Pixel Art with blurry outline in Game Window 1 Answer

Age of Empire Mini Map 1 Answer

Sprite cutoff/altered in game view but not scene view 0 Answers

How to de-pixelize pixel art (smooth out) 2d 0 Answers

Weird pixel displacement in the middle of the screen? 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