guycalledfrank / bakery-issues

Bug tracker for Bakery
4 stars 0 forks source link

Excessive bake times in GenerateVertexBakedMeshes (with solution!) #130

Closed ptbarnaby closed 2 years ago

ptbarnaby commented 2 years ago

On a reasonably simple scene I was seeing lightbakes go relatively quick but a long time spent after the lightbakes were complete before Unity would resume. This seems to go up with the number of mesh renderers in the scene rather than geometry complexity.

On investigation it turned out the majority of the time (about 128 seconds in my case) is spent in GenerateVertexBakedMeshes() and further that it was the call to AssetDatabase.CreateAsset() taking up much of the time.

After a quick google I found that wrapping the GenerateVertexBakedMeshes() call with AssetDatabase.StartAssetEditing() and AssetDatabase.StopAssetEditing() calls made it vastly faster (in my case 5 seconds). I'd recommend wrapping any bulk CreateAsset() calls like this.

guycalledfrank commented 2 years ago

That's a fantastic suggestion, thanks! I didn't know about StartAssetEditing. Even on my little test scene I can see 4x time improvement, and it's gonna be really helpful for large scenes. Just pushed, should be downloadable through the patcher: https://github.com/guycalledfrank/bakery-csharp/commit/3e285689ad6350aa61f4a125aa30e87f57270752

:)