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.

2D lighting not working on tilemap

Discussion in '2019.2 Beta' started by ayockel90, Jul 29, 2019.

  1. ayockel90

    ayockel90

    Joined:
    Jan 27, 2019
    Posts:
    17
    I got 2D lighting working on my sprites using the tutorial below


    But the lights seem to have no effect on tilemaps (walls and floors in my case), even though it's targeting all sorting layers
    https://imgur.com/a/Vokp9iv

    How can I get 2D lights to affect tilemaps?
     
  2. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,322
    I haven't watched the video. Do the sprites you use on your tilemaps and your tilemaps renderers have a material with normal maps?
     
    ayockel90 likes this.
  3. ayockel90

    ayockel90

    Joined:
    Jan 27, 2019
    Posts:
    17
    Here are screenshots of both in the inspector

    https://imgur.com/a/u9pgM1q
     
  4. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,322
    Your tilemaps has the "sprite-default" material. Being 2D it cannot react to light.

    Are you sure they don't mention that in the tutorial you are following?

     
    GabrielC15 and ayockel90 like this.
  5. ayockel90

    ayockel90

    Joined:
    Jan 27, 2019
    Posts:
    17
    That's definitely the issue as all other objects are using Sprite-Lit-Default. However, tilemaps do not allow me to select Sprite-Lit-Default as the material, only Sprites-Default?
     
  6. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,322
    The video I just posted is about adding custom materials to sprites; it's the same process for tilemaps.
     
  7. ayockel90

    ayockel90

    Joined:
    Jan 27, 2019
    Posts:
    17
    Excellent, thanks! I have one more issue if you don't mind.

    The point light appears in the Scene view, but doesn't appear in the Game

    https://imgur.com/a/54Id0Bp

    Why could this be?
     
    zchek likes this.
  8. zchek

    zchek

    Joined:
    Dec 8, 2014
    Posts:
    7

    I had the same issue, setting the light to 0 on the Z (same as the sprites) made it work in game. Weird that it would display at any Z in the scene view but not in game.
     
    Last edited: Aug 5, 2019
  9. a71223639

    a71223639

    Joined:
    Aug 3, 2019
    Posts:
    1
    in my case, I set the Z position of its transform really high (500+) and works.
     
  10. ayockel90

    ayockel90

    Joined:
    Jan 27, 2019
    Posts:
    17
    That was it!
     
  11. RoboYak

    RoboYak

    Joined:
    Apr 16, 2013
    Posts:
    2
    Here are the precise steps I went through to set up my TileMap with lighting. I had to fumble a bit, and thought to post in case it helps someone else.

    1. Find Sprite-Lit-Default Material in your Packages folder (you must have installed the 2D lighting package). Packages > Lightweight RP > Runtime > Materials > Sprite-Lit-Default. You can create a custom material and add the Lightweight RP shader if you prefer. Packages > Lightweight RP > Runtime > Shaders > 2D > Sprite-Lit-Default, and then you would drag this shader onto your custom shader. If these paths change in the future you can navigate there by selecting something with the Sprite-Lit-Default material on it (if none in the scene drag a new sprite in and it will auto have it) and click on the material in the Renderer.
    2. Click on your TileMap and replace the Default Sprite material with Sprite-Lit-Default Material.
    3. If everything works your TileMap will turn black.