Unity: Sprite stretch issue

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?


Game Development Asked by Tikeb on November 14, 2021

1 Answers

One Answer

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.

Answered by Kevin on November 14, 2021

Add your own answers!

Related Questions

Ask a Question

Get help from others!

© 2021 All rights reserved.