2D Light disappears when the camera does not see its object

Hi guys!
So today I updated Unity from 2020.3.15 to 2020.3.42
And I have a new problem - when the camera doesn’t see the object to which the 2D light source is attached (but the light itself should be falling on objects from outside the screen) - the light disappears. Below I give a video

Here’s a screenshot from the editor of what I’m talking about, the object (gizmo) outside the camera

I’m pretty sure that after updating Unity resets some setting. Can you tell me why this happened?

Another funny detail is that right after the update I first tested my project in the editor, where this bug was not there. Then I build - it appeared there. Then I decided to double-check the editor - and in the editor it appeared. Either I’m going crazy or something changed after the build.
I’ve been developing my project for 1.5 years, so I’m very worried, honestly I didn’t want to update Unity at all.
Thanks!

This seems like a problem with the culling / bounds. What happens if you delete the light and put a new one with identical properties?

IF that works and if this is a prefab, you could try Copy Component onto the prefab, checking the Debug Mode to make sure hidden properties are also identical to your recreated light?

IF that doesn’t work, what happens when you recreate the light with a different kind of light? For instance, if this is a freeform light, what if you create highly similar sprite light? (Or vice versa if this is a sprite light.)

I recently updated to Unity 2020.3.43f1 and I am running into the same issue. Global Light 2D and Point Light 2D work as expected, but any Freeform 2D, Sprite 2D or Parametric 2D lights all have this issue. When you first create a 2D light it appears normal in the editor, it can go to the edge of the editor window and remain visible as expected. When you play the game however, the lights disappear at the edge of the screen. When you stop playing the game and you are in the editor again the issue is now visible and reproducible in-editor, not just when playing the game.

Deleting and recreating the lights yields the same results. When first created, the light looks fine in editor. During play and after play, the lights disappear at the screen/window edges.

It looks like this issue was logged in the Issue Tracker, but it is marked as “By Design” and the Resolution Note doesn’t appear to be useful. I don’t have “Alpha Blend on Overlap” checked for any 2D lights and changing the “Light Order” doesn’t make a difference.

100% same thing, every detail

If you’re getting desperate you could fork the 2D Renderer so at least this doesn’t affect your project.

Looking around, I’m guess these lines have some kind of error, in a file called Light2DCullgResult

 public void SetupCulling(ref ScriptableCullingParameters cullingParameters, Camera camera)
        {
            Profiler.BeginSample("Cull 2D Lights");
            m_VisibleLights.Clear();
            foreach (var light in Light2DManager.lights)
            {
                if ((camera.cullingMask & (1 << light.gameObject.layer)) == 0)
                    continue;

#if UNITY_EDITOR
                if (!UnityEditor.SceneManagement.StageUtility.IsGameObjectRenderedByCamera(light.gameObject, camera))
                    continue;
#endif

                if (light.lightType == Light2D.LightType.Global)
                {
                    m_VisibleLights.Add(light);
                    continue;
                }

                Profiler.BeginSample("Test Planes");
                var position = light.boundingSphere.position;
                var culled = false;
                for (var i = 0; i < cullingParameters.cullingPlaneCount; ++i)
                {
                    var plane = cullingParameters.GetCullingPlane(i);
                    // most of the time is spent getting world position
                    var distance = math.dot(position, plane.normal) + plane.distance;
                    if (distance < -light.boundingSphere.radius)
                    {
                        culled = true;
                        break;
                    }
                }
                Profiler.EndSample();
                if (culled)
                    continue;

                m_VisibleLights.Add(light);
            }

            // must be sorted here because light order could change
            m_VisibleLights.Sort((l1, l2) => l1.lightOrder - l2.lightOrder);
            Profiler.EndSample();
        }

You could test if this code is at fault by making it consider every light visible. Then refine it to be a bit more permissive by expanding the light’s boundingSphere.

Thanks for the feedback! I found a fix that worked for me. I ended up uninstalling URP 10.10.1 (which was the default for Unity 2020.3.43f1) via the Package Manager and then manually added the package for URP 10.10.0 to my ‘Packages’ folder in my project. I recreated my ‘UniversalRenderPipelineAsset’ and ‘New 2D Render Data’ objects and now the 2D lights are behaving as expected. So it looks like the bug was specific to URP 10.10.1 and going to the slightly older version fixed things.

Here is a link to the URP package I ended up using: Release 10.10.0 · needle-mirror/com.unity.render-pipelines.universal · GitHub

2 Likes

Same issue on 2020.3.44f1. There’s an update to 2020.3.45f1, did anyone try it?

1 Like

Our team specifically needs to be on version 2020.3.43f1 for console porting purposes, so we won’t be changing right now. If you do upgrade I’d be interested to hear if that resolves things though.

1 Like

It doesn’t.

Thank you, saved me from a massive headache. Always baffling how an LTS update that barely changes anything can still break something.

What’s even more baffling is not allowing us to rollback to older package versions knowing new bugs are being introduced every update.

2 Likes

Has anyone found a fix for this issue aside from rolling back their version of URP? Currently running into this as well on 2021.3.34f1. I suspect it’s the same problem as the bug mentioned here:

https://forum.unity.com/threads/2d-spotlights-flickering-depending-on-camera-position.1438651/