Light2d randomly not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By joe_b
:warning: Old Version Published before Godot 3 was released.

I have bumped into a random issue with my game. It’s a 2D game with a bullet that I want to emit light as it travels across the screen. When it works it look good and I like it. But randomly it doesn’t light up. I used to instance the bullet and I’d have the issue where some bullets would be lit and others wouldn’t. I thought, well, maybe it’s because I’m instancing the scene, so I tried adding several bullets off-screen and moving them onscreen and apply force to them, and when done moving instead of issuing a queue_free() I just stop their momentum and move them back off screen. But alas, the problem remains although with one difference. Now all of the bullets either work or they don’t until you restart the program and you then have a chance that they will either work or not. I’m not sure if I’m doing anything wrong or if this is a bug.
Working:

Non-working:

I’ve tried this on a couple different computers. The OS I’m developing on is MacOS. I haven’t tried on Linux or Windows yet. Another thing, I tried the current Stable build (2.1.1 and a Development build 2.2 Alpha) I am experiencing the same behavior on both Godot versions.

One more thing to note, my player character has a Light2d as well, but it’s set to “Mask” mode, not “Add” like the bullet. The Light2d on the player always works I’ve never had it fail yet. So could it be an issue in the “Add” mode?

OK it’s not “Add” mode, Light2d is randomly not working even with my bullets set to “Mask” mode.

– Update –
So I decided to try to duplicate the problem outside of my game with a simple test app. No scripting just what you see for nodes, I made a couple images for the lighting textures. I have a simple sprite to act as the background. Another sprite with a light2d set to mask. And finally another sprite with a light2d set to “add”. After restarting the app about 10 times or so I was able to show the “add” mode light2d not working, same bug duplicated without any code nothing moving nothing new being added to the scene and only a couple light2ds on the screen.
Working:

Not Working:

I do think there’s a limit to how many lights can be in the screen at the same time (or was that in Unity?). Anyways, try shooting slowly and see if it fails anytime, then repeat the process but shooting fast. I remember seeing an option to change how many lights it could handle (or was that in Unity?), so you’re not hopeless if it’s this.

(I did find an light_discard_enabled option in project settings > render, but I’m not sure what that does)

mateusak | 2017-01-04 22:22

Thanks for your reply mateusak, I’m not sure about the limit, but on the screenshots you see above there were only two Light2d nodes on the screen for both screenshots. One for the player, and one for the bullet. I also tried slowing the bullet down, but that had no effect either. I messed around with the light_discard_enabled option in setting, but neither setting had any effect. I did however make a discovery. If I disable my character Light2d in mask mode I am able to fire all the bullets I want on the screen without issue. I wonder if it’s the two different modes of Lighting on the screen at the same time interfering with each other. I’m thinking I’ll get rid of the Light2d on the player for now until this bug gets fixed… (if it is a bug).

joe_b | 2017-01-05 02:24

I was not saying to slow the bullet, but to shoot slowly :stuck_out_tongue:

Anyways, if you use a mask light just to black out everything around your player, you can use a CanvasModulate for that, and use a add light instead. Other than that, I don’t really know what’s causing your issue.

mateusak | 2017-01-05 06:33

I know what you meant. I did both. Like I said there was only one bullet on the screen at the time each screenshot was taken. They only get shot one at a time anyway. Trust me I messed around with this for days before posting this. The only reason I am posting this is to find out if it’s a known bug, which I’m guessing it’s not. I can make things work by not using a light2d on my player, but it SHOULD work which is my point.

joe_b | 2017-01-05 19:34

I got the same problem also in mac…
a character with a light2d inside his node… that never fail
and other lights that work or not randomly…
in my case i set up all the lights in mix mode…
again… no problem is detected if i take off the light of the character, but should work…
i think is a bug and should be revised
my lights are statics … without movement.

Antilo | 2019-03-11 16:43

Having this problem as well, though on windows… Seems to have something to do with the mere existence of a mask light…

minekpo1 | 2022-10-19 17:19

:bust_in_silhouette: Reply From: minekpo1

Not an answer, but a work around:

As this seems to only affect tile maps:

  • move the light2d in mask mode onto a different light layer.
  • Duplicate your tilemap, setting one to the light layer with the mask light
  • add a canvas material to the other one and set it’s light mode to light only
  • make sure the light only copy renders over the other one