Why does my lighting change after scene is reloaded?

For reloading the scene I just use this simple snippet of code:

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

Now, when I click “Play” button, the scene is nicely lit - colors of the skybox reflect in the white cubes and capsules (that I have not yet gotten rid of), when I change the skybox the light changes too.
But when the space ship crashes and the level is reloaded all that nice lighting goes away and I just see very sharp shadows and colors are not related to the skybox at all. If I stop the game in the editor and play it once again, it happens once again (nice light at the beginning, not so nice after a crash).

My guess is it has something to do with some optimizations that run when the scene is reloaded but not when it is “Played” from editor? But I can’t figure out how to consistently get either one or the other.

1 Like

Hi anula,

Did you generate the lighting? See Window > Rendering > Lighting Settings.

Are there any error messages in your console when the scene does not look good anymore? And which version of Unity do you use?

It seems I indeed did not generate the lighting correctly. I pressed the button a few times in the past but did not attach it to the side bar. Since the generation seems to take ages without any visible progress I had probably always clicked out of that before it actually finished.
I am not completely sure why it is so slow, as I have quite a beefy PC, but it might have something to do with me running it on Linux.
I did not see any errors in the console after reloading the scene, unfortunately.

A followup question: what does it mean to “bake” the lighting? To fix my problem, I clicked “Generate the lighting” and then “baked” them. Would it work even if I didn’t bake them? (I am guessing baking is for performance reasons so they do not need to be generated at runtime?) . I would experiment with it further but each attempt is slow and I think it doesn’t always finish successfully (though if it is true it fails silently).
I also tried using the GPU option (it is marked as “preview”), but that one fails pretty quickly and reverts to CPU.

I am using Unity 2020.2.4f1.

1 Like

It might well be that you’ll have to wait a couple of minutes until the lighting generation is completed. There is a progress bar in the bottom right corner of Unity while Unity is busy generating the lighting.

I am not completely sure why it is so slow, as I have quite a beefy PC, but it might have something to do with me running it on Linux.

I don’t use Linux but maybe you can check somewhere if Unity uses the GPU instead of the CPU to perform certain tasks, and if it can use enough RAM.

Also please feel free to ask our helpful community of students over on our Discord chat server. Maybe somebody has a tip for you.

what does it mean to “bake” the lighting?

It means that your computer generates the lighting of your scene once and uses it. Imagine there is a lamp on the wall, and the light is just there on the wall. You could bake the lighting, so the light becomes part of the texture. Then you could disable the real-time lighting for that lamp which will have a positive impact on the performance because the computer won’t have to calculate the lighting over and over again during runtime. It’s a common technique for optimising the performance.

You would not bake the lighting for the rocket, though, because the rocket and its lamps/spotlights/whatever move, so the light they are emitting during runtime must be calculated during runtime.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms