Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Adding custom Material to TileMap, seems to break it?

Discussion in '2D' started by JarioMen, Jun 7, 2020.

  1. JarioMen

    JarioMen

    Joined:
    May 29, 2020
    Posts:
    3
    Hey Guys, quick question for you all!

    I was playing around with 2D tilemaps, and created 2 different tilemaps, one for walls, and one for plaforms.
    I wanted the platforms one to reflect lights in the scene, so I created a new Material, added the Normals, and when I applied the material to the Tilemap, the tilemap seems to hide behind the "walls" tilemap.

    If i disable the renderer in the walls tilemap, the platform tilemaps can be seen.

    If I use any other kind of Material on the "Walls" tilemap, both tilemaps are rendered, but if one tilemap uses a random material, and another one uses the "Default-Sprites" Material (Or the Sprites shaders), then the tilemap using the random material won't show up.

    Do you guys have any idea why this might be happening?. I player around with the sorting layers, but couldn't manage any progress

    Couple of Images:

    Both Tilesets with the Default Material

    upload_2020-6-7_0-29-48.png

    Adding the "Platform" material to the "Platforms" Tileset

    upload_2020-6-7_0-35-35.png

    Disabled the renderer on the "Walls" Tileset

    upload_2020-6-7_0-36-20.png

    Layers:

    upload_2020-6-7_0-38-3.png
     

    Attached Files:

  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Could you share what your custom shader/material looks like? Thanks!
     
  3. JarioMen

    JarioMen

    Joined:
    May 29, 2020
    Posts:
    3
    Sure!, sorry about the late response.

    upload_2020-6-14_18-7-50.png
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Thanks for the screenshot!

    You likely have an issue with sorting which you can find out more from https://docs.unity3d.com/Manual/2DSorting.html. The default Sprite shader belongs to the Transparent Queue, while this belongs to the Opaque queue (as the rendering mode is Opaque). This means that the Tilemap with this material will be draw first, while the other Tilemap with the default Sprite shader will be drawn over the first Tilemap. Depending on how you want your Tilemaps to be ordered for rendering, this can be wrong.

    You can use the Frame Debugger to see how the Tilemaps are drawn in the GameView. Hope this helps!
     
    pjw2379 likes this.
  5. JarioMen

    JarioMen

    Joined:
    May 29, 2020
    Posts:
    3
    I checked the Frame Debugger, and you were righ!, The Transparent Queue was drawing over the Opaque queue. I changed my material so that it would be Transparent too, which did solve the issue, but I felt that wasn't the correct solution. I played around some with the Ordering Layers, but no dice.

    I ended up solving this issue by moving my Tilemaps in the Z axis. Now, my "Walls" tilemap has position (0,0,1) while my "Patforms" tilemap is in postiion (0,0,0), and that makes it render properly. Thanks for the help!