If I “play” one of the scenes in my game by pushing play in the editor, everything looks fine (bottom photo), but if I load that scene programmatically (using SceneManager) the shadows are extremely dark/pitch black, (top photo).
I’m using URP. All of this is happening in the Editor, the difference being that if the scene is open and I press play it works right, but if while playing I load a difference scene, it looks wrong.
The code that loads the scene is exactly one line long:
The problem is the scene that you will load using your code, And from the editor it seems fine, That is because in the editor when you load it by clicking on it the editor sets up all the lighting for it, This doesn’t happen in playmode
This is how to fix this:
Open the scene that you want to load.
Now go to Window → Rendering → Lighting.
Click on the scene tab (Should already be clicked by default).
Now click new on the Lighting Settings Asset field.
And now you can load from anywhere, If your Lighting Is Generated, Then you won’t have the dark scene issue, Because it will load and the lighting will already be generated!
Hope it Works.
Shouldn't "autogenerate" take care of that? What does autogenerate do if not? And yes, this does seem to help, but not consistently, and having to go thru 30+ scenes and redo this each time it breaks is, "breaking" me.
You don't need to go through each scene again and again, What you should do is create a lighting settings for each of your scene then just generate lighting, and auto generate if checked will re generate when you make changes to objects in the scene, if you make no changes there is no need to bake again, Because the lighting is saved to the lighting settings., So doing just once for each scene providing you don't change anything after that in that scene it is good to go.
So you can't share a single lighting settings for all the scenes that are the same (skybox, fog level, etc?), you need a separate one for each scene? Or am I misunderstanding you? Come to think of it, I currently have a single lighting settings file shared across all scenes, but I'm still able to tweak all the Realtime lighting params without it changing those parameters in other scenes.
Having a single lighting settings, Hmm, You see because each scenes lighting data must be different, Because that file that unity creates holds the baking data, now surely your scenes aren't exactly the same, So the baking needs to be unique, you can't share lighting data across scenes, So I think you could use a shared lighting settings but changing it will still need you to re bake all for the changes to be in affect.
I am using 100% realtime lighting. No baking. But baked lighting makes a subfolder under the scene's folder, so I don't really think it's all stored in the lighting settings file. Are you sure about that?
I found a workaround but it still seems like a bug on unity’s part or a deep misunderstanding on mine (probably the later). All I need to do is add this line to some GameObject’s Start method:
DynamicGI.UpdateEnvironment();
In my case I used my character controller since I can be sure there’s always one and only one of those in each level. At least on my machine the function is so fast there’s zero harm/perceptible delay to calling it once per level. The intended purpose of this function suggests that unity is not applying my skybox or has an “invalid” cached result which is why I’m get black shadows (zero ambient light).
This obviously overlaps with the suggestion that I need to click "Generate Lighting" but does not explain why I have to repeat that process several times a week, as each time I “squash” the bug in one scene it appears again in a different scene. The root cause and the “final” solution remains unclear, at least to me. But that one line of code is a reliable stopgap fix.
Shouldn't "autogenerate" take care of that? What does autogenerate do if not? And yes, this does seem to help, but not consistently, and having to go thru 30+ scenes and redo this each time it breaks is, "breaking" me.
– xeosDYou don't need to go through each scene again and again, What you should do is create a lighting settings for each of your scene then just generate lighting, and auto generate if checked will re generate when you make changes to objects in the scene, if you make no changes there is no need to bake again, Because the lighting is saved to the lighting settings., So doing just once for each scene providing you don't change anything after that in that scene it is good to go.
– hamzakhan201021So you can't share a single lighting settings for all the scenes that are the same (skybox, fog level, etc?), you need a separate one for each scene? Or am I misunderstanding you? Come to think of it, I currently have a single lighting settings file shared across all scenes, but I'm still able to tweak all the Realtime lighting params without it changing those parameters in other scenes.
– xeosDHaving a single lighting settings, Hmm, You see because each scenes lighting data must be different, Because that file that unity creates holds the baking data, now surely your scenes aren't exactly the same, So the baking needs to be unique, you can't share lighting data across scenes, So I think you could use a shared lighting settings but changing it will still need you to re bake all for the changes to be in affect.
– hamzakhan201021I am using 100% realtime lighting. No baking. But baked lighting makes a subfolder under the scene's folder, so I don't really think it's all stored in the lighting settings file. Are you sure about that?
– xeosD