Switching BAKED lights during RUNTIME in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you know how in unity you have runtime lights that can be enabled and disabled while the game is running as you see I have made a simple script with switches lights on and off and while they obviously switch they don't look as good as they could if they were baked like you have that plain black dark Corners which aren't enlightened and they just look bad so let's switch those lights to Big mode instead of runtime and enable them and in the light settings we just bake the current night map and as you see it looks a lot better than before I mean it's a bit too bright but you can adjust it however you prefer but if we now Run the game and well try to switch over lights off well they don't really switch now mainly because the lights are not baked so to fix that we are going to modify our light switch script and as you see that's the script that switches the lights it has of course an array of lights that we switch here's the code that turns them on and off and it also uses new input system so let's switch back to Unity for a second so you know how in unity you have your scene and when you bake your lightning Unity creates a folder of set scene which contains all the light map data and if you look at the name of those light Maps you will see that they have deer and Light which is really what we need so we are going back to our script and let's reference them by making four arrays of texture 2D and for this tutorial I will only be making two bacon light Maps darkened price but you can of course do more so you know how Unity has this cool class called light map settings well it has a field called light maps and that's what we are going to use as you saw before light map accept only an array of light map data so let's make two private Fields called Dark Light map and bright light map which are an array of light map data and now in start function first let's make a list of light map data and emit Darkly might and then we make a for Loop that Loops over the length of the first array and that for Loop adds a new light map data to the list and asynch the values to the light map data and lastly we turn that list to another array and assign it to the dark light map array let's do the same for Bright Light map now we just need to switch the light maps on the button press we do it by writing light map settings equals dark light map and the same for Bright Light map now let's go back to Unity and now we have four arrays for light directions and colors but as you see we only have bright light map files so let's create folder for dark light map files and call it dark light map and also create bright light map folder copy those files and paste it in bright light map folder now let's make dark light Maps we will disable every light but leave only on the door one and we go to the light settings and bake the lightning and after it bakes the scene should updates to dark light map and we should also see the files update now let's copy the dark file map folder and now let's assign the dark wounds to the dark light map arrays we select only the directions by selecting one and holding Ctrl and we drag it to the dark light map direction and then we select only the light ones and drop it to the dark light map color and we do the same for the bright ones now let's save the scene and run it and as you see after pressing buttons one and two the light map should update
Info
Channel: Clicky
Views: 6,087
Rating: undefined out of 5
Keywords: baked lights, unity, lightmaps, tutorial, baked, lights, switching, clicky, runtime
Id: 2dsGZt-kBAk
Channel Id: undefined
Length: 5min 18sec (318 seconds)
Published: Tue Apr 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.