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.
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.
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.
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.
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?
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.
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.
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.