Version: Unity 6.6 Alpha (6000.6)
Language : English
Scaling sprites dynamically using 9-slicing
9-slice a sprite

9-slicing

9-slicing is a 2D technique that allows you to resize a spriteA 2D graphic objects. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. More info
See in Glossary
without creating multiple sprites for all the different sizes.

To use 9-slicing, you create a sprite with nine sections. The different sections stretch or repeat in different ways to keep the sprite in proportion.

9-slicing is useful for creating patterns, walls, or floors in a 2D environment.

Note: You can only use a Box Collider 2D or Polygon Collider 2D component to add a collisionA collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary
shape to a 9-sliced sprite. For more information, refer to 9-slice a sprite.

9-slicing modes

If you don’t use 9-slicing, the entire sprite stretches when you change its dimensions.

A square floor sprite.
A square floor sprite.
The same sprite resized so its wider. The floor, walls, and corners all stretch horizontally.
The same sprite resized so it’s wider. The floor, walls, and corners all stretch horizontally.

With 9-slicing, you can resize the sprite using sliced mode or tiled mode.

Sliced

In sliced mode, the sprite does the following:

  • The corners stay the same size.
  • The top and bottom borders of the sprite stretch only horizontally.
  • The left and right borders of the sprite stretch only vertically.
  • The center stretches horizontally and vertically.
The same sprite in sliced mode, resized so its wider.
The same sprite in sliced mode, resized so it’s wider.

Tiled

In tiled mode, the sprite does the following:

  • The corners stay the same size.
  • The top and bottom borders of the sprite repeat horizontally.
  • The left and right borders of the sprite repeat vertically.
  • The center repeats horizontally and vertically.
The same sprite in tiled mode, resized so its wider.
The same sprite in tiled mode, resized so it’s wider.

You can control how Unity repeats the texture across the resized sprite. For more information, refer to 9-slice a sprite.

Additional resources

Scaling sprites dynamically using 9-slicing
9-slice a sprite