0

Unity has the ability to set boundaries for a sprite. This allows me to stretch the image without losing quality and save borders. This is usually used to create menus and pop-ups. I add such a sprite through the UI - Image menu, it is displayed as Image, and the desired stretching occurs. The problem is that I can't repeat the same thing by inserting a sprite through the menu using 2D Objects - Sprites. It is added to the game as a Sprite Renderer, which simply stretches the original sprite, ignoring its boundaries. How can I achieve sprite stretching when adding through 2D Objects - Sprites?

Result

Sprite settings

What I want to reach

I tried adding an Image component, but after that the sprite stops displaying at all.

1
  • First you should decide what exactly you want to use this for ... If this is about 2D UI you should use a proper Canvas + Image component.. or go for UI Toolkit. If it is rather for interacting with other sprite renderers then yes go for that ... But here it seems you would rather want to go with the UI as it seems to be sort of a speech bubble Commented Sep 22, 2024 at 15:13

1 Answer 1

2

Change the draw mode (the first dropdown) from "Simple" to "Sliced" in the SpriteRenderer inspector, and use the Size property (or a RectTransform) instead of the object's scale to change its size.

From Unity - Manual: Sprite Renderer:

Property Function
Draw Mode Define how the Sprite scales when its dimensions change. Select one of the following options from the drop-down box.
Simple The entire image scales when its dimensions change. This is the default option.
Sliced Select this mode if the Sprite is 9-sliced.
Size ('Sliced' or 'Tiled') Enter the Sprite’s new Width and Height to scale the 9-sliced Sprite correctly. You can also use the Rect Transform Tool to scale the Sprite while applying 9-slicing properties.
Tiled By default, this mode causes the middle of the 9-Sliced Sprite to tile instead of scale when its dimensions change. Use Tile Mode to control the tiling behavior of the Sprite.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.