0
\$\begingroup\$

I have Unity version 6000.0.30f1, and I've started a new 2D project with the option Universal 2D - Unity’s Universal Render Pipeline pre-configured with 2D Renderer.

I'm adding jpg image to assets. This image is displayed correctly when used as sprite directly. When used in material with Universal Render Pipepline/2D/Sprite-Lit-Default as a shader (default option) it shows properly in New Material tab. When trying to use it as a material on a simple sprite like a Square, sprite remains white.

What could be wrong?

I tried different settings, shaders like Unlit, checked tiling, offsets, texture type, lighting source etc. Checked project's settings regarding URP.

I tried to use simple material with "Unlit/Color" and this one works fine on this sprite. Lighting is working, Light 2D color influences a sprite from jpg and Square sprite.

The same approach worked with same image for older project for Unity 2020 with URP manually configured.

When I use 3D object like Cube, applying the same material on it works ok in the same project.


TLDR answer: For 2D project, using graphics as a material textures won't work automatically for Sprites (Sprite Renderer). Some solutions are proposed below. Another approach is to use 3D objects with a Mesh Renderer on which such texture works automatically (so basically switch to 2.5D project).

\$\endgroup\$
1
  • \$\begingroup\$ Please do not edit answers into questions. Answers should always be posted in the Answer section. \$\endgroup\$ Commented Jan 14 at 18:46

1 Answer 1

0
\$\begingroup\$

The SpriteRenderer component automatically replaces the diffuse/base texture of the material that is assigned to it with the Sprite asset assigned to the SpriteRenderer. When you don't have a sprite assigned, then it uses the plain white placeholder sprite instead.

Which means you need to assign the JPG with the base texture to the Sprite of the SpriteRenderer. You can then use the properties of the material for additional special effects like normal mapping.

\$\endgroup\$
5
  • \$\begingroup\$ But Sprite of the Sprite Renderer is built-in white "Hexagon Point Top". Is there an option to assign JPG image to it? Or, if I understand you correctly, should I create Sprite with this image already included? In general, I don't want to create a custom hex with this image. I wanted to create a prefab of such hex (like a "base" hex) without material, and later create prefab variants of each hex with different images. I was able to do this in 3D before, using a hex created in Blender, but with 2D and this built-in shape it's not working. Here's how it looks currently: ibb.co/GvmnBxj \$\endgroup\$ Commented Jan 13 at 23:12
  • 1
    \$\begingroup\$ You could make a custom material that takes a texture parameter and then clips that texture against a hexagon shape (using either math, or a second texture parameter for a hexagon-shaped mask), but this is not the best way to implement a hexagonal sprite. Your Blender mesh solution is much better, because you don't have any overhead of a second texture, and no overdraw outside the hexagon borders. Details like "I am trying to mask an image to a hexagon to use as a tile" are the kinds of things that should have been included in your original question. \$\endgroup\$ Commented Jan 14 at 2:56
  • \$\begingroup\$ @JohnMoore If you want to use images to define the shape of the sprite, then perhaps a sprite mask is what you actually need. \$\endgroup\$ Commented Jan 14 at 9:11
  • \$\begingroup\$ @DMGregory I wanted to create a full 2D game, i.e. use plain 2D objects like built-in one. However, it seems that it requires more work than just make 2.5D game. \$\endgroup\$ Commented Jan 14 at 17:43
  • \$\begingroup\$ @Philipp Quite the opposite, I wanted to use built-in ready shapes and use images only as a textures. Thanks to both of you for your insights, I will probably switch to a 3D project and try 2.5D approach. I'll mark this answer as the solution. \$\endgroup\$ Commented Jan 14 at 17:45

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.