Search Unity

Question URP 2dLight Sorting on Canvas, Make Sprites unaffected by some lights

Discussion in '2D' started by KingKonXI, May 12, 2023.

  1. KingKonXI

    KingKonXI

    Joined:
    Apr 9, 2019
    Posts:
    22
    Hi All,

    I have a 2d project where i enabled the URP to be able to use 2d Lights. I managed to get them working using the Sprite-Lit-Default material and an additional camera. Also the Canvas is set to Screen Space- Camera.

    The issue I am having is, that SortingLayers seem to have no effect, or at least not the effect which I am looking for ( i tried "sorting layer of canvas", "target sorting layer of the 2d light" and "sorting group components").

    What I am trying to achive is the following:
    I have a street lamp with attached 2d light which needs to illuminate itself (this works) this lamp is on a layer in the foreground. The player is behind the lamppost and its spotlight therefore should NOT illuminate the lamp.
    How can I achive this effect?
    Like how can I disable some lights to not affect certain assets which are in front while keeping the asset lit from other lightsources?
    Basically I would need something like keeping the 2d light on the same layer as its image asset.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Canvas is UGUI UI thing, it's not a 2D feature and not related to Sprites so it's not clear how it's relevant here.
     
  3. KingKonXI

    KingKonXI

    Joined:
    Apr 9, 2019
    Posts:
    22
    Hi Thanks for your reply,
    The "player" element is a transparent video loop which is necessary since there are a lot of frames at HD resolution. the scene therefore is displayed in a canvas element and all the other assets are therefore spawned into the canvas or subcanvas for that matter. Not sure if there is a better solution, but sofar it works very well regarding what i am trying to achive exept for the sorting of lights (eg excluding assets on other layers from being lit)