Baking lightmaps from script (Batch mode)

Hello,

I am trying to bake lightmaps from batch mode (as an automated process on our build machine), but noticed the lightmaps generated in this context are incorrect, lacking sky ambience.

I noticed this error in the log, which makes me worry this might not be possible.

Static Lighting Sky is not ready for baking. Please make sure that at least one frame has been rendered with HDRP before baking. For example you can achieve this by having Scene View visible with Draw Mode set to Shaded

Is there any way to automate lightmap baking in HDRP in batch mode? Is there a method I can call to force HDRP to update the static lighting?

Thanks for the help

Couldn’t you just wait at least one frame before baking?

You should also be able to call Camera.Render to force a frame to render, before trying to bake ?

I have tried to manually call render on the scene view camera, but this doesnt work in batch mode, but does work in editor (there is no scene view camera in batch mode obviously). I will try to create a temporary camera in the scene and force render that.

I have tried creating a camera and rendering that before baking, but still get the static sky lighting error.

GameObject bakeCameraGO = new GameObject("BakeCameraGO");
bakeCameraGO.hideFlags = HideFlags.DontSave;
HDAdditionalCameraData hdData = bakeCameraGO.AddComponent<HDAdditionalCameraData>();
Camera bakeCamera = bakeCameraGO.GetComponent<Camera>();
bakeCamera.Render();

Lightmapping.Bake();

There is no scene view in batch mode, waiting a frame does not render anything.

You don’t need a scene view for rendering to happen afaik. The rendering should happen as usual (I think) whether you are in batchmode or not (this won’t probably apply if you throw a nographics flag, but I don’t think that this is the case). You should be able to do it with editor coroutines probably as baking the lightmaps won’t be probably possible during the playmode.

I just tried using editor coroutines, rendering with a fresh camera manually, then waiting several seconds, then baking lightmaps, and I still get the initial error and incorrect probes.

have you tried running your automation process without the batchmode to verify that everything is working as expected to verify that it is indeed batchmode only issue?

I just tried running it out of batch mode, and it works fine :slight_smile: Definitely seems to be a batch mode issue.

I am wondering what you are using to automate your light bakes? Is it a custom tool you wrote or did you find one? I am trying to find a way to bake out a bunch of scenes without having to manually open each one and click the bake button for a project I am working on.

1 Like

We are using jenkins to call an editor script we wrote. This is still an issue for us :frowning:

Hello

I hate to bump, but has anyone managed to bake lightprobes correctly from batch mode, as part of an automated build pipeline?

We get somewhat correct probes, but they are missing sky ambience.

Currently we are launching in batch mode, then starting an editor coroutine, which opens the scene, waits 5 seconds, renders, waits 5 seconds, then calls Lightmapping.Bake. This is an attempt to get unity to generate the ambient lighting, which seems to be an asynchronous process.

When we run this method from the editor, it works fine, but running via command line in batch mode gives incorrect results.

I’m running out of ideas for hacks to make this work :slight_smile:

Thanks

1 Like