I am sorry if this kind of question has been answered already. I want to bake (Generate) light by C# script (Not in run-time mode). I have uploaded the screenshot if you are confused. Kindly guide me.
Also is it possible if i want to do it during run-time mode? Anyone please guide me regarding this all. Thank you so much.
I never did this, but a quick search told me that you should be able to manually bake it using the Bake() function: Unity - Scripting API: Lightmapping.Bake
So as long as you have the Lightmapping object and run Bake() on it, you can do that through script.
Also, please dont use pointless polls like that. Polls are very niche. If you want the opinion of the community on whether or not they agree with a feature request you are making or smth, then a poll can be useful. For questions such as these (especially if there is only one answer), a poll is absolutely meaningless and just takes up space.
You can do this kind of thing. Basically you just open the scene, and then call bake.
EditorSceneManager.OpenScene(someScenePath);
Lightmapping.BakeAsync();
There’s a bit more to it, looking at the progress of the bake via `Lightmapping.isRunning’, but that’s the gist. I have an editor script that opens a list of scenes one at a time and bakes them one after the other using this approach.
Thank you so much for the solution. But I have still one more question didn’t answered yet, is it possible if I want to do it during runtime?
Well, you said not in runtime in your original post. And as far as I know, there’s no way to bake lightmaps at runtime. And I can’t imagine you’d ever really want to, given how long it takes to bake lighting. You’d make players sit there for minutes waiting for the lighting to bake.
One thing you can do is bake multiple sets of lightmaps, and swap them at runtime. There’s a thread on it here, but I don’t know the specifics on how to bake multiple lightmap sets. There’s a github project for that, though: GitHub - laurenth-personal/lightmap-switching-tool: Tool that allows switching different baked lightmap sets on a unity scene at runtime.
I actually asked both ways, see the screenshot. Btw, thank you so much for helping me out
Actually I am not working on game. It;s a kind of rendering app. User will add room items in the play mode and then click on render, and he can wait for finishing baking in run-time. I want that way
In that case, it seems it might be best to treat your use case as a Unity editor extension, rather than something to use in play mode. That might not be to your liking though, as it means your users would need to be running Unity. But for the kind of thing you’re trying to accomplish, I expect you’ll have a much easier time if you can make use of all of the editor-only functionality available in the Unity editor.
Is there any similar example available? Kindly send me link if available, I want to do it
There’s probably a bunch of tutorials on how to write editor extensions in Unity. The basic docs explain some of the simple things:
Other than that, I’d search for videos that might show how it’s done. A large number of assets you can purchase rely on custom editors.