Skip to content

UV Mapping Tutorial

calligraphy edited this page Oct 13, 2023 · 4 revisions

What are UV maps?

Put simply, UV maps tell Unity how a texture is applied onto a 3D object. It might help to think of UV maps as wrapping paper around a present. If you have a difficult shape to wrap around, like a teddy bear, then the wrapping paper looks crumpled and distorted.

Each vertex has a U and V pair of coordinates, like it has X, Y and Z coordinates. The UV coordinates are laid out on a UV map, which Unity uses to wrap the texture around the object.

Good UV mapping can look really stylish, and bad mapping can make the map look buggy.

Tutorial Breakdown

To start, open the scene UV Mapping found under Assets/Scenes/Tutorial Levels.

Here we have a complete level, but oh dear- the UVs are all misaligned!

You’ll see the level geometry under Static sorted into different parts. In each part you’ll be able to align some UVs and show you the ropes.

  • Part 1 - UV Basics

  • Part 2 - Box Project

  • Part 3 - Rotating & Scaling

  • Part 4 - Autostitch

  • Part 5 - Automatic vs Manual UVs

  • Part 6 - Curves & QuadUV

  • Part 7 - The Final Exam

You’ll also notice there’s a disabled section called Answers - feel free to have a look if you need some help. Just check the box to enable them in the Inspector!

There’s also some powerups and core gameplay elements hidden in the scene. So the scene is ready to export and play when you’re finished.

Let’s work through each part step by step and make this level look tidy.

Part 1 - UV Basics

This part will teach you how to interact with UVs in the UV editor, and make basic edits.

UV Basics 1

  1. Select UV Basics 1 in the Hierarchy.

  1. In face select mode, select the top face, and then open the UV editor in the ProBuilder toolbar.

  2. You’ll see that the selected face on the platform is selected in the UV editor.

Pro-tip - Move the UV editor so that you can see the UV editor and the level editor at once.

  1. If you move the object around using Move Tool, you will see that the texture moves as you move the UVs around.
  2. Align the UV face in the editor so the tiles are aligned with the platform.

Pro-tip - Hold Ctrl whilst moving the UV face to snap the face to the grid.

UV Basics 2

  1. Select UV Basics 2 in the Hierarchy.
  2. In vertex select mode, open the UV editor and select a vertex on the distorted face.
  3. If you move the vertex around, you’ll notice the UV map becomes distorted.
  4. Select the vertex, and move it to make a square in the UV editor.

UV Basics 3

  1. Select UV Basics 3 in the Hierarchy.
  2. Open the UV editor in vertex select mode.
  3. Drag the vertices on the distorted face and move it to make a square in the UV editor.

Part 2 - Box Project

In this part we learn about box project, a UV tool helpful for square platforms. It’s helpful also for simplifying UVs.

Box project acts like a projector pointed from the X, Y and Z axis, wrapping the UVs flat against the geometry.

Box Project 1

  1. Select Box Project 1 in the Hierarchy.
  2. In face select mode, open the UV editor and select the distorted face.
  3. In the UV editor, change the UV mode to Manual. We’ll cover the difference between Manual and Auto UVs later.

  1. Press Box Project. The UVs will be aligned.

Box Project 2

  1. Select Box Project 2 in the Hierarchy.
  2. In face select mode, open the UV editor, and drag and hold to select the distorted faces all at once.
  3. Change the UV mode to manual, and press Box Project. The distorted UVs will be aligned.

Box Project 3

Box Project is just a projection, so sometimes geometry needs cleaning up after using Box Project.

  1. Select Box Project 3 in the Hierarchy.
  2. In face select mode, select the trims on both sides of the platform and apply Box Project onto them.
  3. Note how the trims are still not aligned. Using edge select mode, select the short edge of the distorted trims.
  4. Move the edge up and down until the UV becomes rectangular and the trims are aligned.

Note - Planar project is like box project, but projects from the normal of the face. It has its uses, but generally speaking for Marble It Up! level editing Box Project is almost always the way to go.

Part 3 - Rotating & Scaling

In this part we learn about how rotating and scaling in the UV editor can be useful.

Rotating 1

  1. Select Rotating 1 in the Hierarchy.
  2. In face select mode, select all the faces on the top of the platform and box project them. Note how there’s still some cleaning up to do.

  1. Use the move tool to align the tiles correctly.
  2. Some of the trim is still misaligned. Select the rotate tool, and the misaligned faces.

Pro-tip - Hold Ctrl whilst rotating the UV face to snap the angle to the grid.

  1. Rotate the UVs until the trim lines up as shown below.

Scaling 1

Not all materials scale to the right size after using box project.

  1. Select Scaling 1 in the Hierarchy.
  2. Select all the faces, and Box Project all the materials. Note how the sides are not correctly scaled.

  1. Using the Scale Tool, select the sides and scale the UVs down to make the texture appear larger.

Pro-tip - Hold Ctrl whilst scaling the UV face to snap the scale to the grid.

Note - Scaling UVs to be smaller in the UV editor makes the texture appear larger.

  1. When the UVs are the right size, move them to be aligned correctly.
  2. Look at the bounce surface. Notice how the hexagonal pattern is not visible.
  3. Select the bounce surface and scale it down until the hexagonal pattern is visible.

Note - There isn’t a right size for the bounce surface scale, so just scale it until it feels right.

Part 4 - Autostitch

In this part we learn about autostitch, a feature which lets you stitch 2 UVs together providing they share an edge. It’s particularly useful for UVs on trims and curves.

Autostitch 1

Here is a platform with 1 tile correctly aligned in the centre. Here we will see how autostitch can fix UVs quickly.

  1. Open the UV editor. Autostitch only works with the UV editor open.
  2. Select the face of the blue tile in the centre.
  3. Holding Ctrl, select an adjacent face to the centre tile. You will notice that the face stitches to the previous face.
  4. Holding Ctrl, repeat this until all of the faces are correctly stitched.

Autostitch 2

Here we will use autostitch to fix the rainbow trim on the level. Autostitch is particularly useful as it lines up the UVs to form a continuous rainbow gradient.

  1. Select the neatly UV’d face, and holding Ctrl, click on the adjacent faces to autostitch it. Notice how the trim is aligned.
  2. Continue to autostitch around the trim until all of it is neatly UV’d. Make sure to do the top and bottom too.

Pro-tip - The rainbow trims show different gradients dependent on their orientation. Pay close attention to get the results you want!

Autostitch 3

This time we use autostitch to align UVs on a half-pipe. Half of the faces have been done here as an example. Since there’s a lot of faces, this can be quite tedious without autostitch to do as box project doesn’t work here.

  1. Selecting the aligned tile face at the bottom, autostitch the UVs up the side of the quarter pipe.

  1. Note how the faces don’t align up perfectly with the trim. With the scale tool, select all of the faces which were just auto-stitched.
  2. Right click and hold the handle in the UV editor, and drag it around. Hold Shift to snap it to vertices. Snapping the handle to the bottom of the selected vertices, scale the UVs until they line up properly with the trim.

Note - You might need to individually adjust some of the edges of the UV, holding Ctrl to snap them to the grid.

  1. Notice how the arrows are facing the wrong direction.
  2. Selecting the face with arrows, drag it around. You’ll notice that the UVs it was stitched to are also being dragged around.

  1. To unstitch the UVs, select the face you want to separate, and press the Split UVs button in the UV editor.

  1. Rotate and scale the arrows around until they are facing the correct direction.

Part 5 - Automatic vs Manual UVs

So far the UVs we’ve worked with have been Manual UVs. Manual UVs have the advantage that the UV map does not change when you adjust the geometry. Automatic UVs on the other hand scale and adjust when you move geometry. Generally, manual UVs are preferred to be used. Automatic UVs can be useful, but can change unpredictably, for example if you change the pivot of an object.

Automatic UV 1

Here is an instance where automatic UVs can be useful. We are looking to connect the bridge between the 2 platforms. Let’s try joining the platforms together.

  1. Select the edge of the bridge, press the Select Holes button in ProBuilder and you should have the ring of edges selected.

  1. Drag the edges to the right to connect the bridge to the other side.

  1. Notice how the UVs are stretched when you do this. This is because the UVs were manual UVs so the UVs are not changed when you edit the geometry.
  2. Undo the last step, or move the edges back to their original position.
  3. Select the ring of faces in the UV editor. Press the button Convert to Auto to convert the UVs to automatic UVs.

Note - Automatic UVs are highlighted blue in the UV editor when selected, whereas manual UVs are highlighted orange when selected.

  1. Now select the edges of the bridge and drag the bridge to join the platforms. Note how the UVs automatically scale when you move the faces around.

Automatic UV 2

Similar to the last example, we are looking to connect 2 platforms together with a bridge. This time the faces are already automatic, however there’s an incline.

  1. Select the edges with the Select Holes ProBuilder tool, and drag them to meet the base of the other platform.
  2. Now drag them up to create a ramp. Notice how the UVs shift and do not line up anymore, especially on the sloped trim.

  1. Move the edges back to the bottom of the base again.
  2. Select the faces of the bridge in the UV editor. Press the button Convert to Manual to convert the UVs to manual UVs.
  3. Now select the edges of the bridge and drag them to join the platform. Notice how the UVs are not shifted and are correctly aligning with the rest of the tiles.

Note - When you create an object, or extrude faces, the UVs will default to be automatic.

Part 6 - Curves & QuadUV

Curves can be quite daunting to UV. However, a well built curve is just a series of quads. This means that if the UVs can be made square, everything will align neatly.

Remember this rule: Make UVs square to make smooth looking curves! Provided the geometry is well planned out, the rest is smooth-sailing.

Curves 1

Starting off simple, we will fix just one face of a curve.

  1. Select the face with the broken UV in the UV editor. Notice how the other faces are rectangular in the UV editor.
  2. Move the two vertices of the face so that the face becomes rectangular in the UV editor.
  3. The face will be aligned with the rest of the curve.

Curves 2

Moving on, let’s try something a little harder.

  1. Select the broken UV faces in the UV editor.
  2. Once again, we are looking to make the UVs rectangular like before. Move the vertices to become rectangular and the texture should appear aligned in the scene.

Pro-tip - Using the scale tool, select all the UVs in a line and scale to 0 by holding Ctrl. This will align all the selected UVs into a vertical or horizontal line and saves time when making UVs square.

Curves 3

  1. Once again, we are looking at the same piece of geometry. This time we will use the QuadUV tool to speed the process up.
  2. In the Marble It Up drop down menu, select the Open QuadUV Window option.
  3. Once the QuadUV window has opened, select all of the misaligned faces.
  4. Press Quad UV Faces. This will move all of the faces into one tile at the origin of the UV editor.

  1. Selecting the vertices, increase the size of the square so that 2 tiles appear on the face.

  1. Once finished, spread out the tiles. This is important as it ensures there is a unique noise map on each of the faces and the tile noise is not repeated.

Part 7 - The Final Exam

Here's a test for you - can you complete the final hexagonal piece and make it look like it does below?

Tackle each area bit by bit, and find which tool works best to get the job done. Pay attention to the small details!

Tips & Best Practice

  • If you are UVing a complex shape, start by making the UVs square, or at least opposite lines parallel.

  • Design your level geometry with UVs in mind! If your geometry is poorly thought out, applying UVs will be even harder. Try to use quads, and avoid polys with more than 4 sides where possible.

  • UVs take patience and practice. Don’t worry if they’re not perfect!

  • If you find the texture is distorted after aligning UVs, try adding in polygons/sub-dividing them can help reduce distortion.

  • Some distortion is okay!

  • Target 4 trim to 1 tile, but this rule isn't constant if you are UVing a curve, where the stretching may cause it to be 6 trim to 1 tile.

  • If box project or other UV tools don't line up well in the editor, it could be a sign that the geometry is not line up properly.