Generate Lightmap UVs for Editor Combined Mesh

Hi,

I have combined meshes in the editor, and the plugin itself did not regenerate lightmap uvs like I could if I just imported the mesh. How can I generate the lightmap UVs in this case?

1 Like

Hey! Did you find solution? I have the same problem :frowning:

Hey @keninger , @CGDever ,

There’s a few ways to get the UVs, e.g.:

4 Likes

Thank you! It works!
But sometimes for some meshes I get such error :

UnityException: You can generate UVs only for meshes with vertices inited.
UnityEditor.Unwrapping.GeneratePerTriangleUVImpl (UnityEngine.Mesh src, UnwrapParam settings)
UnityEditor.Unwrapping.GeneratePerTriangleUV (UnityEngine.Mesh src, UnwrapParam settings) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Unwrapping.bindings.cs:43)
UnityEditor.Unwrapping.GeneratePerTriangleUV (UnityEngine.Mesh src) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Unwrapping.bindings.cs:37)
UnityEditor.Unwrapping.GenerateSecondaryUVSet (UnityEngine.Mesh src) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Unwrapping.bindings.cs:52)
StairRailing_Corrector.meshBacker () (at Assets/Units/Rooms/Part_2/Bridge/Scripts/StairRailing_Corrector.cs:330)
StairRailing_Corrector.UpdateColliders_And_Mesh () (at Assets/Units/Rooms/Part_2/Bridge/Scripts/StairRailing_Corrector.cs:188)
Bridge_Corrector_Abstract.SaveMeshAsAsset () (at Assets/Units/Rooms/Part_2/Bridge/Scripts/Abstract/Bridge_Corrector_Abstract.cs:73)
Bridge_Corrector_Abstract_Editor.DrawButtons () (at Assets/Units/Rooms/Part_2/Bridge/Editor/Scripts/Abstract/Bridge_Corrector_Abstract_Editor.cs:12)
StairRailing_Corrector_GUI_Editor.OnInspectorGUI () (at Assets/Units/Rooms/Part_2/Bridge/Editor/Scripts/StairRailing_Corrector_GUI_Editor.cs:29)
UnityEditor.InspectorWindow.DoOnInspectorGUI (Boolean rebuildOptimizedGUIBlock, UnityEditor.Editor editor, Boolean wasVisible, UnityEngine.Rect& contentRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1625)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Do you know the reason???

This error is thrown when there are no vertices in the mesh (vertex count is 0). Apart from the mesh simply not having that data, one other reason could be that you called Mesh.UploadMeshData and passed true into the markNoLongerReadable parameter, which will deallocate the CPU-side data.

I’m doing this and it works…but every single UV island is miniscule, about 1 pixel across in the lightmap.
It’s a lowpoly VR game so I am manually combining entire scenes into single figure drawcalls. I suspect this issue is because the resulting combined mesh has a massive bounds compared to any individual UV island? The scene lightmaps fine if I don’t generate combined meshes, but I can’t copy those UVs unless I can guarantee all the meshes that get combined are using the same lightmap page.

You can control which lightmap a MeshRenderer will go on by assigning it a Lightmap Parameter Asset (Unity - Manual: Lightmap Parameters Asset) with a custom Baked Tag in the inspector. Renderers with the same tag go on the same lightmap. Perhaps this is useful to you?