Game asset processing3 min read

Unity UI icon stretched? Check Preserve Aspect and layout bounds

Use a square icon and two tall slots to separate the visible sprite, layout rectangle and click area in Unity uGUI.

Unity UI icon stretched? Check Preserve Aspect and layout bounds
A stretched gem and a round gem inside equally tall menu slots
Concept illustration

A perfectly round skill icon can become oval in a tall inventory slot. Test the Simple Image component in Unity uGUI before changing the art. This fixture targets a single Canvas icon. Nine-sliced borders use different controls.

Run a two-slot test

  1. Draw a circle that nearly fills a square sprite and add thin crosshairs. Assign it to two Image components under the same Canvas. Give both a 100-by-160 RectTransform, with identical anchors, centered pivots and unit scale.
  2. Turn on Preserve Aspect for the second icon only. With the layout held fixed, the first circle looks taller than it is wide. The second occupies about 100 by 100 units and leaves roughly 30 above and below. The Inspector should still show 100 by 160 for both layout rectangles.
  3. With a Graphic Raycaster present, enable Raycast Target on the aspect-preserved Image and leave alphaHitTestMinimumThreshold at its default of zero. Try the empty bands. They can still intercept clicks under rectangle-based hit testing. For a button that owns the whole rectangle, put the raycast on the button background and disable it on the decorative icon.

Retest the sprites you ship

Use Sprite Sheet Packer to organize the icon artwork, then repeat the check on the Sprite imported by Unity. If the centered icon still looks offset, inspect uneven transparent padding and confirm the layout group leaves the intended rectangle in place.

Recommended tools

Ready to try "Unity UI icon stretched? Check Preserve Aspect and layout bounds"?

Use our online tools to apply this tutorial to your indie game project right away.