Search Unity

lightmap generation stuck on preparing for bake

Discussion in 'Global Illumination' started by formatc2013, Mar 24, 2020.

  1. formatc2013

    formatc2013

    Joined:
    Jul 4, 2016
    Posts:
    30
    I have a project set up for Android in Unity 2019.2.21.
    I am using Gamma color space & LWRP.
    And Progressive GPU lighmapper.

    I am trying light my scenes with baked lightmaps combined with just a couple of lightprobes.
    I am using low poly assets with a few materials, nothing special. I created 2 scenes this way with no issues. The more visible stuff gets a lightmap, small insignificant thins get lit by probes. I had to change the scale in lightmap propery though, on a few occasions, but managed to get good results, and Unity was responsive, too. In the third one I am using more area,(a bigger ground and more houses, trees props etc) thus I am using more lightmaps...

    TLDR:

    Tried lowering settings, decrease lighmap size etc and using probes for more objects with no luck.
    Also tried adding more virtual memory to the paging file in windows.
    Deleted GI cache, restarted PC.


    Problems:
    -baking process gets stuck on Preparing bake, but Unity is responsive
    -Unity freezes up
    -comes up with a Windows out of memory message and crashes

    But on a few occasions it baked in seconds with no probs.


    I7 4770k
    16GB RAM
    EVGA 1070

    Is it a bug? Should I report it?
     
  2. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    There are known issues with excessive memory consumption in the GPU lightmapper when baking lightprobes which have been fixed in recent versions.
     
  3. formatc2013

    formatc2013

    Joined:
    Jul 4, 2016
    Posts:
    30
    Thanks! What versions?
     
  4. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    That would be 2020.1.
     
  5. FishStickies94

    FishStickies94

    Joined:
    Jul 27, 2019
    Posts:
    70
    Any chance this is going to be fixed in 2019 LTS considering that's meant to be the production reccomended version?
     
  6. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    @uy3d I would also like to know. Will this be back ported to 2019.4? Our project is becoming unusable due to light probe usage and baking works about 10% of the time now
     
  7. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    There are no plans of backporting this to 2019.
     
  8. FishStickies94

    FishStickies94

    Joined:
    Jul 27, 2019
    Posts:
    70
    So to get this straight, a pretty serious bug that get's in the way of a pretty big aspect of the engine is not being solved in the Longtime support version? So it's either move to 2020 and deal with all the bugs and preview stuff in that or stick with LTS and deal with this pretty severe bug.

    Class support from Unity as always.
     
    Nosada, d1favero and ElectroLlama like this.
  9. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Please try the latest 2019.4 LTS version, you are on 2019.2 which doesn't have as many bugfixes. If the problem persists please file a bug report. Thanks!
     
  10. ElectroLlama

    ElectroLlama

    Joined:
    Dec 8, 2019
    Posts:
    2
    I'm also having this issue occasionally with 2019 LTS. Started at a lightmap size of 512 and it baked fine in 5 seconds or so. Went up in increments to 2048 and it bogged down in "Preparing to bake". I aborted, then went back to 512 (clearing the data) and it sat in "preparing for bake" for 6-8 minutes while the CPU pegs at 95% or so. When it's actually baking with the GPU the CPU use is negligible. If I wait that full 6-8 minutes on a lower setting, then bakes just fine with the GPU on every manual iteration of Generate Lighting. I was definitely using my GPU as the baking device.

    I went through this whole cycle a few times but after restarting Unity, I can't replicate it anymore. Exiting and reloading helps when this happens, then I'm back to normal speeds on 2k or 4k maps.
     
  11. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Did you submit a bug report as the staff member asked? Let me know so I can let them know by providing the ID number.
     
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    This happens for quite a few versions now. The first bake of the day happens consistently fast, then something gets stuck and eventually it becomes really slow or unresponsive. It has been happening on multiple projects, on multiple machines, in multiple Unity versions.

    There probably is no bug report, because there is no point in making a bug report, since if the issue is not 100% reproducible, then it might as well not exist.

    Next you'll tell me you still think that interactive / progressive updating still works.
     
    d1favero likes this.
  13. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    I hate to say just forget about it... but Bakery really is many times better. The only problem is that baking isn't as fast, but it is way higher quality, for less runtime memory usage.
     
  14. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    We have just recently fixed an issue where progressive bakes were not working for the first bake of an editor session, regardless of the lighting settings.
     
  15. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    Bakery GPU is actually faster & uses less GPU memory than Progressive GPU, it also results in higher quality lightmaps, though that part is a bit subjective. (and offers other optional features like SH directional lightmaps, as first seen in the Frostbite engine on Battlefront 2).

    We put them head to head comparing results with image diff tools and measuring bake times at different settings, in order to decide what lightmapper to use for production on a very large project (this was in 2018.x unity).
    We had scenes that Progressive GPU could not bake, and the Progressive CPU was not an option because it would take multiple days to complete.
    Bakery can still run out of memory, but will still handle more than what Progressive GPU can.

    Bakery is not a 100% drop in replacement though IMO, but it depends on the scope of the project. There are still occasional artifacts that can show up from the denoiser and other issues, so a non-programmer may encounter problems that would otherwise be easily solved with use of a debugger and small code fixes in your project.

    The downside to Bakery is it has to work around Unity's lightmap storage arrays which are cumbersome to work with, so the C# codebase is a bit of a mess. On serious projects, developers may have to alter how Bakery loads in lightmaps to work with how you are storing and loading assets from bundles etc. (we had to)

    The way lightmaps (and in general any per-object render data) is stored within Unity could use a full rethink & opening up to users for customization, as it would benefit serious developers greatly, but I'm unaware of any efforts toward that.

    btw, I actually found this thread because a project using 2019.4.4f1 is getting the stuck on "Preparing Bake..." indefinitely issue.
     
    Last edited: Feb 8, 2021
  16. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    How do the lighting settings come into play?

    On 3 different computers, with 2 different projects using built-in I have not seen progressive baking work 99% of the time (since 2019LTS), the only times it actually updated anything was when I had very low sample settings and filtering on, which is kinda useless.
     
  17. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    The lighting settings store the prioritize view flag. It didn't matter whether the flag was enabled or not, every first bake of an editor session wasn't picking it up and defaulting to view prioritization being disabled. After the bake finished, the flag would be picked up, and subsequent bakes would do view prioritization if it was enabled in the lighting settings.
     
  18. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    Prioritize view is called "progressive updates" in recent versions of Unity.

    I'm confused on whether with the flag off I'm supposed to see any updating. It used to be that the whole map was slowly updating when the flag was off, and with the flag on it was doing the parts that were visible in the scene view first.

    Now, with the flag off, there is no updating happening at any time. Bake starts, and at some point it ends.

    When checking "Progressive Updates", I get updates but only in the parts visible in the scene view. (after the first bake as you said, due to the bug).

    What is the intended behaviour when the flag is off?
     
  19. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    With progressive updates off, a lightmap will bake to completion before any filtering or denoising is applied.
     
  20. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    I wasn't clear enough. Let's take filtering and denoising out of the equation and assume that I have those off.

    With Progressive Updates OFF and filtering OFF, if I press bake, am I supposed to see any updates happen to the lighting as it bakes? <- The current behavior in my experience is that if I have both of those off, I press bake, then I see absolutely nothing change for the duration of the bake, and then suddenly, after the bake is complete, I see the final lightmap.
     
  21. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Yes, this is intended behaviour, the lightmap will composited and become visible once it has been baked to completion.
     
    soleron likes this.
  22. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    Please update the manual then.
    https://docs.unity3d.com/2020.2/Documentation/Manual/progressive-lightmapper.html
    And maybe even change the name.
     
    Last edited: Mar 9, 2021
    d1favero likes this.
  23. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
  24. Deleted User

    Deleted User

    Guest

    I ran in to this problem today, where I got stuck on Preparing to bake. I seem to have found a weird fix to it, but I'm not entirely sure if it was just a visual thing. I pressed down my right mouse button on the scene (the tool to look around in the scene) and the Baking text with an ETA would appear. I made sure to hold the button down for the duration until baking was complete, if I released it went back to Preparing to bake... Very odd.
     
    GermaniumSystem likes this.
  25. GermaniumSystem

    GermaniumSystem

    Joined:
    Jun 23, 2020
    Posts:
    1
    Thank you for sharing this. I spent the better part of a day trying to get my lightmaps to bake and got nowhere. No matter what I did, Unity would just sit there, stuck on "Preparing bake" for hours until eventually crashing. But, simply holding down right click got everything to finish baking in 30 seconds. This behavior is just bizarre and I would have never thought to try that if you hadn't suggested it.
     
  26. bhoffman67

    bhoffman67

    Joined:
    May 14, 2022
    Posts:
    20
    I tried your trick Rikard... to no avail :(
     
  27. wbstafford

    wbstafford

    Joined:
    Oct 5, 2017
    Posts:
    6
    For anyone interested, I just ran into this issue as well. The message would say "preparing bake" and if you examined it it showed a progress of 96%, but never went anywhere. The "estimated time" just kept going up from 1 second on, and nothing ever happened.

    After much work, I figured out the cause in my case. I am using probuilder objects in my scene, and I somehow had a probuilder "cube" that was empty. Not even sure how that happened, but there was a "cube" built in probuilder that had no size or shape. It was essentially an empty gameobject created by probuilder. This was the culprit. Deleted that thing and baking works again.

    Quite a pain to figure out but I hope this helps someone down the road.
     
    pachermann likes this.
  28. EMartorell

    EMartorell

    Joined:
    Nov 8, 2015
    Posts:
    2
    I came across this issue recently, and managed to find the cause.
    I started by disabling all my static geometry and enabling the entities one at a time until the bake stopped working.
    It turns out that a few objects were using a custom shader graph material (animated UVs + emission). Once disabled (or made non-static) I could bake normally.
     
    pachermann likes this.
  29. pachermann

    pachermann

    Joined:
    Dec 18, 2013
    Posts:
    133
    Same here disabled all Meshes in the Scene, and turned on one by one and then i found out what asset killed the Baking process.
    also kept the Lightmap Preview window open once a lightmap got baked to see it the mesh lands in the layout.
    - Somethimes when i touched the editor when it was hanging it suddenly worked and loaded the lightmaps then. Unity 2021.3.24f LTS
     
    Last edited: May 11, 2023
  30. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    pachermann likes this.
  31. pachermann

    pachermann

    Joined:
    Dec 18, 2013
    Posts:
    133
  32. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    I have the same issue with 2022.3 LTS. Switching to CPU or GPU doesn't work.
     
  33. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    Are you perhaps using Realtime GI as well? That can often look like the bake is stalling when it's actually just generating the inputs for the bake.
     
  34. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Nope. It was turned off. And the light source is mixed mode.
     
  35. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    can you submit a bug report please?
     
    Horus-Glass likes this.
  36. jvetulani

    jvetulani

    Joined:
    Dec 20, 2016
    Posts:
    55
    Is this planned to be fixed in 2020.3.47? We've upgraded from 3.41 and encountered it and removing shaders with a time node seems to allow us to render the scene...
     
  37. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Just to update. I changed Max Lightmap Size to 512 and it works. However, it generates to many lightmap files.
     
  38. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
  39. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    Have you submitted a bug report? It is not possible to know what may be the issue only from these posts.
     
  40. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    It pains me to say that we no longer support the 2020 stream and this bug landed right before we ended support for it... I'll try to ask around to see if there's anything we can do, but quite unlikely. Sorry about this.
     
  41. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Cannot. Our project is too big and the uploader took forever.
     
  42. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    Okay, can you send me an editor log of one of the failed bakes?
     
  43. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    No editor log, it only stuck at baking like 8% forever.
     
  44. giorgos_unity

    giorgos_unity

    Unity Technologies

    Joined:
    Nov 14, 2019
    Posts:
    38
    There is an editor log available for every editor session-

    Editor logs
    Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
    MacOS: ~/Library/Logs/Unity/Editor.log
    Linux: ~/.config/unity3d/Editor.log
     
  45. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    @giorgos_unity here it is. I also managed to upload the project successfully.
     

    Attached Files: