Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Baking lightmaps from script (Batch mode)

Discussion in 'High Definition Render Pipeline' started by Chris_Webb, Sep 28, 2022.

  1. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    76
    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.

    Code (CSharp):
    1. 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
     
  2. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    246
    Couldn't you just wait at least one frame before baking?
     
  3. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    501
    You should also be able to call Camera.Render to force a frame to render, before trying to bake ?
     
  4. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    76
    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.
     
  5. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    76
    I have tried creating a camera and rendering that before baking, but still get the static sky lighting error.


    Code (CSharp):
    1.                
    2. GameObject bakeCameraGO = new GameObject("BakeCameraGO");
    3. bakeCameraGO.hideFlags = HideFlags.DontSave;
    4. HDAdditionalCameraData hdData = bakeCameraGO.AddComponent<HDAdditionalCameraData>();
    5. Camera bakeCamera = bakeCameraGO.GetComponent<Camera>();
    6. bakeCamera.Render();
    7.  
    8. Lightmapping.Bake();
     
  6. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    76
    There is no scene view in batch mode, waiting a frame does not render anything.
     
  7. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    246
    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.
     
  8. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    76
    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.
     
  9. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    246
    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?
     
  10. Chris_Webb

    Chris_Webb

    Joined:
    Mar 18, 2014
    Posts:
    76

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