0
\$\begingroup\$

I have a simple png square 8px x 8px. In Unity I've left the pixels per unit at 100 and added the image to the scene to create a prefab of the item. I then add four items to the screen like so:

    var block = Resources.Load("Prefabs/Block", typeof(GameObject));

    Instantiate(block, new Vector3(1f, 0f), Quaternion.identity);
    Instantiate(block, new Vector3(0f, 1f), Quaternion.identity);
    Instantiate(block, new Vector3(2f, 0f), Quaternion.identity);
    Instantiate(block, new Vector3(0f, 2f), Quaternion.identity);

The results (as shown in the image below) seem to stretch the image dependant on where the prefab is placed. Is this normal behaviour? Is there a way round this or something I'm missing?

Image

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This previous Q&A may clarify what's happening here. If you haven't adjusted your camera to account for the size of your display window/screen, then you're very likely scaling your pixel art by a non-integer ratio, resulting in rounding that enlarges some areas more than others. \$\endgroup\$ – DMGregory Jul 21 '20 at 23:26
1
\$\begingroup\$

You haven't given a lot of information here. What components are attached to the block prefab (SpriteRenderer? Image?)? My best guess is that you're looking at imprecise pixel alignment, which can happen when the edges of objects in Unity space are not precisely aligned with pixels on the screen.

If these objects are Images displayed in a canvas, you can try enabling "Pixel perfect" on the canvas. If they are SpriteRenderers, things get a bit more complicated. You might try the official "Pixel Perfect" package, if your entire game requires pixel precision.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you this has helped. The issue was I'm new to this kind of dev. Pixel perfect is exactly what I needed. \$\endgroup\$ – Tikeb Jul 25 '20 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.