Unity Collider Optimizer

Optimizes Mesh & Polygon colliders in Unity.

Polygon Collider Optimizer

Original Sprite Unity Polygon Collider Optimized Polygon Collider
Original Sprite Unity Polygon Collider Optimized Polygon Collider
Path Count 213 paths 23 paths

The tool uses a C# implementation of the Ramer Douglas Peucker Algorithm to smooth the polylines and reduce the number of paths created by a Polygon Collider in Unity.

Usage

  • Download the collideroptimizationpackage_2d_v004.unitypackage package from the Releases.
  • Import all the assets from the package in your unity project.
  • Attach the PolygonColliderOptimizer.cs script on your 2D sprite.
  • Adjust the optimizationFactor to control the amount of optimzation you need.
  • Run the performance comparision test on your machine by cloning the project & going to the Polygon Collider Optimization Test scene in Unity.

Mesh Collider Optimizer

Original Mesh Unity Mesh Collider Optimized Mesh Collider
Original Mesh Unity Mesh Collider Optimized Mesh Collider
Triangles Count 9132 tris 2416 tris

The tool uses the Computational Geometry Unity Library by Erik Nordeus 🐐 to perfrom the Quadric Error Metric simplification on the shared mesh of the mesh collider.

Usage

  • Download the collideroptimizationpackage_3d_v004.unitypackage package from the Releases.
  • Import all the assets from the package in your unity project.
  • Attach the MeshColliderOptimizer.cs script on your 2D sprite.
  • Choose the connecting mode between Fast, Precise, and No.
  • Adjust the optimizationFactor to control the amount of optimzation you need.
  • Choose the mesh style to be Soft, Hard or both.
  • Warning: Choosing the “Fast” mode would likely lead to errors, Precise mode is recommended for most of the meshes.
  • Run the performance comparision test on your machine by cloning the project & going to the Mesh Collider Optimization Test scene in Unity.

Updates

  • Added the functionality to save and load the optimized colliders as assets.
  • Fixed the refresh bug.

Contribution

Contributions to the project are welcome. Currently working on converting the QEM algorithm to a couroutine to stop the main Unity thread from freezing.

Known Bugs

  • If a prefab is made out of a gameobject having Polygon Collider Optimizer, it keeps refreshing itself. [FIXED]
  • Choosing Hard Edge Mesh Style decreases the number of triangles but induces additional vertices (doesn’t affect the performance).
C#, Unity