0
\$\begingroup\$

I am trying to show a single image on one side of a cube in Unity.

But the texture keeps repeating, even if I set the bitmap texture settings to "clamp" instead of "repeat / wrap". (As suggested by most answers here and on other forums).

Even if I create a bigger image with a lot of white (to "wrap" around the cube), that whole image is still repeated on each side of the cube.

How can I show a texture only once, without tiling, on one side of a cube?

tiling settings

repeating texture

\$\endgroup\$
5
  • 2
    \$\begingroup\$ The trouble here is that all six faces of the cube are mapped to read from the (0,0)-(1,1) square of the UV space. So they're not reading "outside" the texture where wrapping settings apply. You either need to make your own cube mesh that's unwrapped differently (i.e. putting the other faces outside the texture), or make a custom shader that ignores the texture based on which face it's drawing (e.g. using the normal vector to determine whether you're drawing the "front" face). You could also build your cube from 6 quads, and only use your textured material on one of the quads. \$\endgroup\$ Commented Jul 22, 2024 at 14:51
  • \$\begingroup\$ Thanks! I was able to create 6 quads, where only one has a texture. Is this a problem for cubes in particular? I also get another error now: "Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported since Unity 5." \$\endgroup\$ Commented Jul 22, 2024 at 15:39
  • 1
    \$\begingroup\$ You probably want a BoxCollider, not a MeshCollider when trying to represent a boxy primitive shape like a cube. If this solved your problem, feel free to document your solution in an answer below. "Is this a problem for cubes in particular" - all meshes will show textures using the texture coordinates they were authored with. If the texture coordinates they were authored with are not the ones you want, you should author a mesh with the ones you want. This rule applies universally to all meshes - what's particular to each case is how you define what it is that you want. \$\endgroup\$ Commented Jul 22, 2024 at 15:51
  • \$\begingroup\$ Note that creating a box with 6 quads is probably going to give you lower performance than creating a box with 1 cube. How much the performance impact matters will depend on how many boxes are rendered at once. \$\endgroup\$ Commented Jul 22, 2024 at 18:56
  • \$\begingroup\$ By "making my own cube mesh" do you mean exporting a cube from Blender and then importing it in Unity? Is this enough to fix the initial problem of repeating textures? I got rid of the "convex" error by just removing all colliders and adding one box collider on the parent element, thanks. \$\endgroup\$ Commented Jul 23, 2024 at 11:57

1 Answer 1

1
\$\begingroup\$

From comments, it looks like you've already found a solution that works. I'll add this in case it helps others with similar issues:

Use two objects

You can draw a texture on one side of a cube without creating any custom meshes by using two objects.

The first object is the Cube, which has the texture you want to display on the other 5 sides of the cube. The second is a single quad, which is parented under the cube, but offset so that it sits just outside one of the faces. This second object should have your face texture.

Any physics or game logic that you want associated with the combined object should be on the cube itself. The face quad should have only a MeshRenderer and other components required for it to work (e.g. no colliders or game logic) - unless you want to add additional components to it to animate the face.

Long term, doing art this way will be a drag on your game's performance (additional game objects come with some overhead), but it's easier to write as it doesn't require opening any 3D modelling tools.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Just watch out for z-fighting if you have two close parallel surfaces like this. There are camera and shader tricks that can reduce it, but it's often more reliable to fix the issue at its source by eliminating the close overlapping geometry wherever possible. \$\endgroup\$ Commented Jul 23, 2024 at 3:04
  • 1
    \$\begingroup\$ I always find it hard to position a object almost but not quite on top of another object. If it's too close you get the strange flickering effect. If it's not close enough you can see a small gap between the objects. For now I went with the "6 quads" solution which seems to work well. \$\endgroup\$ Commented Jul 23, 2024 at 11:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.