Search Unity

Question about Lightmapping.Bake

Discussion in 'General Graphics' started by Patrick_PS, Apr 15, 2021.

  1. Patrick_PS

    Patrick_PS

    Joined:
    Sep 9, 2019
    Posts:
    154
    Hi,

    I want to create lightmaps of (3d) building models for an isometric game (4 directions basically).

    I used to be able to place the building prefab in a scene with a camera and a light and then call Lightmapping.Bake(). In the callback bakeCompleted I would then call Texture2D lightmap = LightmapSettings.lightmaps[0].lightmapColor; and save that file.

    But this is not working anymore, LightmapSettings.lightmaps is always empty when the callback is called.

    I have tried to use Lightmapping.BakeAsync() in a coroutine and yielding until Lightmapping.isRunning is false but the result is the same, no lightmap.

    Is there another way to do this? Is there a known bug?

    (At runtime I manually add the right lightmap to LightmapSettings.lightmaps and then set MeshRenderer.lightmapIndex)

    regards,
    Patrick
     
  2. Patrick_PS

    Patrick_PS

    Joined:
    Sep 9, 2019
    Posts:
    154