Search Unity

Bug Semi-transparent object not rendered in front of map

Discussion in 'General Graphics' started by dtootill, Dec 15, 2022.

  1. dtootill

    dtootill

    Joined:
    Oct 9, 2020
    Posts:
    29
    I'm building a level editor for a game with a tiled map. Some of the objects a player can place (such as trees) are larger than a single tile, so I'd like to show them semi-transparent to allow the player to see the map behind them. Objects normally use the Unlit/Texture shader. To make them semi-transparent, I programmatically switch to the standard shader, which I've configured with an albedo alpha of 150. This works fine in the Unity editor: you can see both the object and the map behind it:
    upload_2022-12-15_10-48-39.png
    However, if I build the game for Windows, the portion of the object over the map is not rendered:
    upload_2022-12-15_10-52-25.png
    I've tried a number of configuration tweaks, with no luck. Is there a way of making the executable render the same way as the Unity editor?

    For background, the portion of the view outside the thick red border is a background image with position.y=-15. The border encloses a grid of GameObjects with position.y=0. The semi-transparent tree has position.y=+15. The camera is directly overhead.
     
  2. dtootill

    dtootill

    Joined:
    Oct 9, 2020
    Posts:
    29
    Just in case anyone has the same issue: there is definitely a bug in Unity with changing a shader's transparency at runtime that only manifests in the Windows executable (and possibly on other platforms also; I tested this issue only on Windows). The workaround that worked for me was to duplicate the material, make one copy opaque and one copy transparent, and swap them when I wanted to change transparency. This works, though it's a little cumbersome when there's a bunch of objects, each with its own material.