Sprite size / pixels per unit / placement in x - big confusion

Hi there,

can someone please enlighten me…
I got a png in the size of 400x400px.
I have imported it as a sprite and set the pixels per unit to 100, meaning: the height of the sprite equals 4 Unity-units.
I have a script that places the sprites so that the first one sits on x=0 and y=0, the next one on x=0 and y=4, then x=0 and y=8. That works great, they fit perfectly together.
Now: I place one sprite on x=4 and y=0 and they overlap quite a bit…they fit together if I set x to 4.36…why?
I know there are some pitfalls with the aspect ration etc. but this also happens when my Camera.main.aspect equals 1.

So will someone point me in the right direction please? :frowning: Thank a lot!

You can see the problem in this picture below:
1956368--126544--placement_error.jpg

Take a close look at the Pivot parameter in the Import Settings of your sprites.
If all your sprites are the same size and should fit together you have to make sure each sprite uses the same pivot alignment. If you have sprites with different sizes e.g. 1x1 and 1x2 and 2x2 you want to move the pivot in a corner so you can stick to integer coordinates.
The camera aspect ratio should not matter as everything is scaled the same way.

1 Like

Thanks for the advice, that is usefull to know. Unfortunately in this case, all the sprites have the same size of 400x400 (or 4x4) and the pivot is in the center for every sprite.

Try to set filter mode to point. If this doesn’t help maybe one of your tiles is not exactly 400px, check them again and try to set the tiles manually in the editor to see if you get the same problem like when you set them with code.

1 Like

Arrrgh…sorry guys! So stupid, one tile was indeed 40 pixel wider than I had thought. Thanks for all the pointers!