- Home /
Pixels to units question
I have a background image for 2D adventure game which is 1024 x 307 in pixels. Pixels to units ratio is set to 100, meaning this image should be about 10 units x 3 units. But, somehow it becomes approximately 60 units wide and 25 units in height. How come ?
I get warning in the inspector on image size not beeing multiple by 4 so it cant be compressed in DXT format, could this be the problem ?
I want to be able to get image width in units, smth like widthInUnits = image.width / ratio (ration beeing 100 in this case), so i get 1024/100 = 10 Units, but in action my image turns out to be 60 units in width... i dont understand how this happnes, which ratio is used ?
I use ortographic camera.
EDIT:
I realized that my image is in fact 6668x2004, and that is what actually gets translated into units, 66 x 20 units, but when i import image into unity it asks me for the "max size" in import settings, that was set to 1024 so when i obtain image.width its 1024. I tryed changing maximum size to 4096 in import settings (which is max sizei can get), but still image.width returns 1024.
I dont understand how Unity actually uses 6668x2004 image dispite max size is set to 1024. And even if max size is set to 4096, image.width still returns 1024...
EDIT 2:
Ok it returns 4096 i was referencing wrong image in code sry
Now the question remains, why does unity use 6668x2004 image in spite of setting 4096 to be max allowed. Should i simply resize my original image to be 4096xSomthing, and never use larger images?
Answer by kacyesp · Sep 02, 2014 at 11:47 AM
Unity is most likely resizing your picture to a power of 2. 307 is an odd number so it's scaling it up pretty big, hence why your unity units is higher than you expected. If your image fits, put in a 1024 256 file, otherwise, use 1024 512.
I edited my question, i realized that my image is in fact 6668x2004, and that is what actually gets translated into units, 66 x 20 units, but when i obtain image.width its 1024. I tryed changing maximum size to 4096 in import settings (which is max), but still image.width returns 1024
Did you hit the apply button after changing the max size?
Edited again, was checking for different immage >.<, now its ok, it returns 4096 as set in import settings
The original image keeps its size. But the image used in your game will be compressed to the max size. It won't be compressed if it's smaller than the max size. And you'll have to combine images or downsize the image to get 6668x2000.
Got it, thx man, now I dont know should I mark this answer as correct cos question "evolved" as i realised few things xD.
Still seems to me that Unity is not resizing my 6668 image to 4096, but i wont bother i ll split my big image into smaller ones
Your answer
Follow this Question
Related Questions
Newbie question 2d positioning and moving 2 Answers
How to change the Width and Height in the script C#? (New Gui Unity 4.6 beta) 2 Answers
rect.Contains cant accept rects with a negative width and height? 4 Answers
Changing height of camera based on device aspect ratio. How? 0 Answers
[UNSOLVED] Get a GameObject width and height in pixels (JS) 3 Answers