Universal Colliders 1.2.0
Generate fast and accurate colliders for Unity
Universal Colliders

Welcome to the universal colliders' documentation!

The Universal Colliders was developed to put an end to the "non-convex collider" problem in Unity. Its goal is to generate colliders dynamically, with a robust method yet flexible and controllable by the end-user or scripts.

This project stems from the object-oriented bounding boxes algorithm, as defined in the 1996 paper OBBTree: A Hierarchical Structure for Rapid Interference Detection. Is is more precise than the AABB-type algorithms, axis-aligned bounding boxes, easily found on the marketplace. It was also developped to be flexible, and to provide as much control as the "user-paint" type algorithms. We extended it to user shapes such as mesh colliders, making it the ultimate tool for colliders generation.

How to use

The basic workflow is simple: choose an object, add the UCollidersRoot component, change the recursion level, and launch the scene. This section goes into a detailed explanation.

UCollidersRoot

This section is a short manual to use this script. Please see the related section for the script reference.

Recursion level

First you need a model with a mesh with "Read/Write Enabled" set to true in the mesh's options. Then simply drag the "UCollidersRoot" script as a component, and choose the recursion level with the slider.

  • -1 means no computation (you do not want to compute any Oriented Bounding Box (OBB).
  • 0 is the general oriented bounding box.
  • For each higher value, we split the OBB in two (if possible). It means that "level x" while compute a maximum of 2x OBBS, that is 1024 boxes for level 10.

When you reach necessary precision, just start the scene, and a set of bounding boxes will be generated as children of an empty GameObject. You are all set!

Colliders preview

The next field it the kind of vizualization you want to have. Choose anything convenient, but keep in mind it is only here for debug and does not modify the scene.

Include Children Meshes

The "include children meshes" property changes the meshes taken into account. By default, we only use the MeshFilter of the associated object, ignoring its children. In some cases you may want to include them in the collisions as well, so check this box if required.

Shape

The colliders' shape field allows you to switch to another kind of shape than a box. By default, we generate oriented minimal bounding boxes. It means that each vertex is enclosed in a box collider. However, it may give inaccurate results when you set a low precision. One solution is to use a higher recursion level. You may also want to change the shape of colliders to spheres, cylinders or mesh.

Boundicity (Shape is Sphere or Capsule)

The way colliders wrap around the mesh. If boundicity is 0, shape will be inside the mesh. With boundicity of 1, mesh is contained in the collider.

Encapsulate triangles

Colliders encapsulate triangles instead of single vertices. Slower but avoid holes around edges.

By default, the script uses vertices only to compute colliders. However it is troublesome with meshes with long edges. Use this option to consider entire triangles (vertices + edges) instead of vertices only.

Note that holes will be avoided, but convergence becomes slower.

Regenerate Colliders

This button generates the UCollidersNode objects without waiting for the scene to start. In case some colliders have already been generated, they will be erased, unless they have the "preserve collider" property checked.

Unpack Colliders

This button will convert UColliderLeaf children into standard colliders GameObjects. It is equivalent to deleting UColliderLeaf components from children manually, though this button also flushes out the data.

Delete Colliders and Data

Flush all the data, and removes associated colliders. Useful for correcting mistakes.

UCollidersLeaf

This is automatically added as a component to mark that a GameObject is in fact a UCollider. You may interact with it, but adding it manually is not supported.

Preserve UCollider

If checked, this UcolliderNode won't be deleted when you hit the "Regenerate Colliders" on his parent.

Shape

The exact analogous of shape in UCollidersRoot, but applies for this specific UColliderOnly.

Subdivide UCollider

Sometimes a computer is just not enough and you need a human. If a specific UColliderNode gives a result too coarse for you, you may force its subdivision manually.

Vertices

This field is simply the list of vertices that shoud be enclosed. You can view it freely but take care as it can be ver long and slows down Unity.

What is an OBB?

OBB stands for oriented bounding box. It is oriented in the way that the OBB rotates to match the approximate "direction" of vertices. On the opposite, methods such as axis-aligned bounding boxes does not apply rotations, creating much bigger boxes.

Troubleshoot

As a general assertion, Universal Colliders performs well on high-poly mesh. If you have no control on your mesh, this section may help you.

General Method

If the generated colliders are inaccurate, here is a solution. The basic workflow to add more precision is:

  1. Use a higher recursion level, without encapsulating triangles.
  2. Use boxes.
  3. Edit your mesh:
    • Try balancing vertices distribution
    • Add more vertices
  4. Do manual edits.

I see "cracks" in the generated colliders

This means your vertices are not very random, so Universal Colliders optimizes colliders by following diagonals. Either makes vertices more random, or try to use the "encapsulateTriangles" property.

Content

Scripts

The only scripts you may interact with are UCollidersRoot.cs and UCollidersLeaf.cs. The other script provide various useful functions for the code to work. In case you need them in your code, you can find them under the namespace UColliders.

Models

The Suzanne model is a standard object generated by Blender. According to Blender's licence terms this model is considered as a part of this package.

Plugins

Math.NET Numerics is a library for numerical computation under MIT License. It is used as a complete library for matrices.

Logos

The main logo of the project is an original creation of Florian.LB. The logo and his variations are a property of this project.

Future developments

We created this package because we thought the marketplace was lacking a robust colliders package. The project went well, so you are welcome to make propositions of future developments.

  • Implementation of recursive hierarchy based on object hierarchy.
  • Extend to deformable meshes (ragdolls and animated).
  • Add a button to merge OBBs?
  • Compute precision and add the ability to generate colliders based on required precision.
  • Add a loading bar when computing colliders
  • Add an "Unpack UCollidersLeaf" button

Contact

If you encounter any problem, want an enhancement, and so on, please join the Discord community. If you enjoyed the package, please let me a review. I made this package because I thought it could be useful, it took me a lot of time for an uncertain result.

The email address for this project is universalcolliders@houmgaor.com. Get in touch!

You can also leave a comment on the website (no email required) https://www.houmgaor.com/.

Enjoy!