In unity 2020.1, Unity added what they call overlap-free packing to their built in UV generation when importing meshes, allowing you to automatically calculate the packing amount needed to get UVs without overlap. However, I generate all of my meshes within editor scripts, which means (unless I’m missing something) I have to generate my lightmap UVs via Unwrapping.GenerateSecondaryUVSet.
As best as I can tell however, there is no way to use the calculate method when calling directly from script. Am I missing something, or is there really no calculate mode when packing in code? Some of my meshes, simple 5 face boxes are generating UVs with unacceptable amounts of overlap.

Check out this manual page: Unity - Scripting API: ModelImporter.secondaryUVMarginMethod
Keep in mind that you can only call to that API when using the MeshImporter.
Thanks for the reply, though I was trying to be clear in my post, I cannot use MeshImporter because my meshes aren’t in a compatible format. It sounds like there is no way to use the API without having a compatible model file to import, which seems like a large oversight. If I need to use the API to generate proper UVs the only way to do so that I can see would be to write the generated mesh to disk and have unity re-import it.
Apologies, I must have missed the part about procedurally generated meshes. There’s no way to access the packing method for such a use case.
Once you’d have a minute, I’d recommend that you’d submit a feature request via this link. Our product managers will take a look.
Thanks for the reply, I’ll have to put something in.
If anyone else stumbles upon this thread, I found some decent UnwrapParam settings from the probuilder package that work a lot better than the default functionality.
public static UnwrapParam GetUnwrapParam(float hardAngle = 88f, float packMargin = 20f, float angleError = 8f, float areaError = 15f)
{
return new UnwrapParam()
{
angleError = Mathf.Clamp(angleError, 1f, 75f) * .01f,
areaError = Mathf.Clamp(areaError, 1f, 75f) * .01f,
hardAngle = Mathf.Clamp(hardAngle, 0f, 180f),
packMargin = Mathf.Clamp(packMargin, 1f, 64) * .001f
};
}
1 Like