[Procedural] Automate LOD Generation for Editor Generated Meshes
Solution
Unity 2022.3.x - Unity 6.3.x
Published Mon, May 4
Developers frequently encounter performance bottlenecks when using procedural geometry because the standard LODGroup system is often perceived as being locked to imported assets. Without a programmatic way to generate Mesh levels of detail, custom-generated meshes remain unoptimized at long distances, impacting rendering budgets and memory usage.
The MeshLodUtility class allows developers to simplify geometry programmatically. This is essential for procedural tools or editor scripts that produce high-fidelity geometry requiring optimization. By invoking these methods within your script, the optimization process is integrated into the asset creation pipeline.
- Reference the source
Meshyou wish to optimize. - Define the reduction thresholds and parameters for the MeshLodUtility logic.
- Call the
GenerateMeshLodsmethod to return an array of simplifiedMeshobjects. - Attach a
LODGroupcomponent to theGameObjectcontaining your script results. - Map the generated
Meshobjects to the appropriateLODlevels in theLODGrouparray.
Additional Tips:
- Use
AssetDatabase.AddObjectToAssetto parent the new MeshLodUtility outputs to the original mesh file to keep the Project window organized. - High vertex counts may increase generation time; ensure the source
Meshis marked as readable in the import settings or memory before processing. - The MeshLodUtility creates brand new
Meshinstances that must be manually destroyed if not saved to theAssetDatabaseto prevent memory leaks.
TL;DR
The MeshLodUtility class provides a programmatic interface to calculate and generate Mesh levels of detail for assets created within the Unity Editor.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.