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.
  2. Dismiss Notice

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

Discussion in 'Universal Render Pipeline' started by Fitbie, Jan 20, 2023.

  1. Fitbie

    Fitbie

    Joined:
    Aug 17, 2021
    Posts:
    63
    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!
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    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.)
     
  3. Volcano-Bean

    Volcano-Bean

    Joined:
    May 24, 2015
    Posts:
    13
    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.

    https://issuetracker.unity3d.com/is...ght-gets-closer-to-the-edge-of-the-scene-view
     
  4. Fitbie

    Fitbie

    Joined:
    Aug 17, 2021
    Posts:
    63
    100% same thing, every detail
     
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    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
    Code (CSharp):
    1.  public void SetupCulling(ref ScriptableCullingParameters cullingParameters, Camera camera)
    2.         {
    3.             Profiler.BeginSample("Cull 2D Lights");
    4.             m_VisibleLights.Clear();
    5.             foreach (var light in Light2DManager.lights)
    6.             {
    7.                 if ((camera.cullingMask & (1 << light.gameObject.layer)) == 0)
    8.                     continue;
    9.  
    10. #if UNITY_EDITOR
    11.                 if (!UnityEditor.SceneManagement.StageUtility.IsGameObjectRenderedByCamera(light.gameObject, camera))
    12.                     continue;
    13. #endif
    14.  
    15.                 if (light.lightType == Light2D.LightType.Global)
    16.                 {
    17.                     m_VisibleLights.Add(light);
    18.                     continue;
    19.                 }
    20.  
    21.                 Profiler.BeginSample("Test Planes");
    22.                 var position = light.boundingSphere.position;
    23.                 var culled = false;
    24.                 for (var i = 0; i < cullingParameters.cullingPlaneCount; ++i)
    25.                 {
    26.                     var plane = cullingParameters.GetCullingPlane(i);
    27.                     // most of the time is spent getting world position
    28.                     var distance = math.dot(position, plane.normal) + plane.distance;
    29.                     if (distance < -light.boundingSphere.radius)
    30.                     {
    31.                         culled = true;
    32.                         break;
    33.                     }
    34.                 }
    35.                 Profiler.EndSample();
    36.                 if (culled)
    37.                     continue;
    38.  
    39.                 m_VisibleLights.Add(light);
    40.             }
    41.  
    42.             // must be sorted here because light order could change
    43.             m_VisibleLights.Sort((l1, l2) => l1.lightOrder - l2.lightOrder);
    44.             Profiler.EndSample();
    45.         }
    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.
     
  6. Volcano-Bean

    Volcano-Bean

    Joined:
    May 24, 2015
    Posts:
    13
    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: https://github.com/needle-mirror/com.unity.render-pipelines.universal/releases/tag/10.10.0
     
    Unrighteouss and Fitbie like this.
  7. davaicyka

    davaicyka

    Joined:
    Feb 23, 2014
    Posts:
    2
    Same issue on 2020.3.44f1. There's an update to 2020.3.45f1, did anyone try it?
     
    Fitbie likes this.
  8. Volcano-Bean

    Volcano-Bean

    Joined:
    May 24, 2015
    Posts:
    13
    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.
     
    Fitbie likes this.
  9. davaicyka

    davaicyka

    Joined:
    Feb 23, 2014
    Posts:
    2
    It doesn't.
     
  10. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    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.
     
    trousergeese likes this.