Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Feature Request [2D Lights proposal]: Target Sorting Layers as an asset

Discussion in '2D Experimental Preview' started by ThundThund, Dec 18, 2020.

  1. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    Hi everybody, this is a tiny proposal that may solve many problems during the development of a game. When you create a light in a scene, you specify the Sorting layers that light affects to, but what happens if that list changes and you have already created 50 lights in 10 scenes? You have to go one by one updating the list of affected layers.

    If you could just have an asset with a list of affected layers then you could assign the Target Sorting Layers property to that asset in every light, so you can change the list later on at only one place, updating all the lights at the same time. This feature could be optional, you can use the asset or just set a value as usual.

    An alternative, instead of using an asset, could be to have a configuration panel somewhere to create layer groups with a name that you could select in the Target Sorting Layers property popup.

    Hope you find this useful and include it in future releases.
     
    GliderGuy likes this.
  2. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    174
    This is something that you could create yourself - add a component to your lights gameobjects and internally configure your layer groups (so later on if you change a layer name or add a layer, you just update your script to reflect your change). Have the component apply the layer group OnEnable or Awake, or wherever you want. Set it ExecuteInEditMode so it applies the layer group in edit mode as well as play mode.

    Edit: I was wrong. The Target Sorting Layers variables "affectedSortingLayers" / "m_ApplyToSortingLayers" are private/internal.
     
    Last edited: Dec 20, 2020
  3. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    Hi JamezOr, thanks for your suggestion, I know I could do that by myself. Even if the property was not private, I think every single programmer that uses the 2D lights would have to create their own component too, so my point is that it should become a built-in editor feature.
     
    GliderGuy likes this.
  4. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    174
    Yeah I see what you're saying - could be a nice addition
     
  5. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    As a "solution" in the meantime, what I'm doing is to create a prefab per type of light, so all lights are instances or derive from them inheriting the Target Sorting Layers value.
     
  6. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    134
    Hi @ThundThund
    I'd like to get a deeper understanding of how well the solution of using light prefabs works for your project. Could you elaborate on what works well and what doesn't?
     
  7. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    For example, I have a Global Light, a Point Light and a Freform Light as prefabs with my default values. They all have the Target Sorting Layers set to the those layers that are affected by lights: "Background" layer and "characters" layer, whereas the "Foreground" layer is not enabled in the list. Then when I need to create a new light in a level, I just drag and drop one of these prefabs. I can change whatever property of the lights in the scene, but the Target Sorting Layers property. If I, in the future, add a new layer that must be affected by lights, I just have to mark it as enabled in the property of the prefabs, I don't need to change the property in every light of every scene to add the new layer.
     
  8. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    Addition: The Target sorting layers of every ShadowCaster2D needs to be updated too when a new sorting layer is created. This may be a huge mount of work.
     
  9. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    Another idea to mitigate this issue: When creating a new sorting layer, we could be asked whether we want it to be added as Enabled by default or Disabled.
     
  10. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
    At least allow us to change the Target sorting layers by code in editor, make it public. I can use reflection but I would rather not do so.
     
  11. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    177
unityunity