meshfx // COLLISION // UNITY
How to add a collision mesh in Unity
In Unity you give a model collision by adding a collider: Box, Sphere or Capsule colliders for simple shapes, or a Mesh Collider that uses a mesh you choose. Assign a simplified collision mesh rather than the render mesh, and tick Convex on any Mesh Collider attached to a Rigidbody that physics moves.
pyrofx effects work today, and new accounts start with $5 of usage.
meshfx measures faults, checks repairs and makes LODs for a triangle budget. meshfx runs on the hosted API: try it in the Playground.
- Primitives: Box, Sphere, Capsule
- Mesh Collider with its own mesh
- Convex: 255 triangles at most
01 // BY HAND
Add a Mesh Collider with its own mesh
- Model a low-poly collision mesh in your 3D editor that wraps the object, and export it in the same FBX as
Crate_Collision, or as its own file. - Import the FBX and select the GameObject that should collide.
- Click Add Component > Physics > Mesh Collider.
- Drag the collision mesh asset into the Mesh Collider's Mesh field, then disable the renderer on the collision mesh if it came in as a visible child.
- Tick Convex if the object has a Rigidbody that physics moves.
- Enter Play mode and check the outline in the Scene view, where colliders draw as green wireframes.
02 // PRIMITIVES
Use primitive colliders where they fit
Box, Sphere and Capsule colliders are the cheapest shapes in Unity's physics. A barrel is a Capsule, a crate is a Box, and a table can be several Box colliders on child objects under one Rigidbody (a compound collider).
The Generate Colliders checkbox in the model import settings adds a Mesh Collider made from the render mesh to every mesh in the file. Use it for static level geometry, where an exact shape is fine because nothing moves.
03 // CONVEX
Why Convex matters
A convex Mesh Collider wraps the mesh with no dents, which lets moving objects test against each other quickly. Unity limits a convex Mesh Collider to 255 triangles, so it builds a simpler hull from a dense mesh. A Mesh Collider without Convex works only on static or kinematic objects.
using UnityEngine;
public class AddCollision : MonoBehaviour
{
[SerializeField] Mesh collisionMesh;
void Awake()
{
var col = gameObject.AddComponent<MeshCollider>();
col.sharedMesh = collisionMesh;
col.convex = GetComponent<Rigidbody>() != null;
}
}
04 // meshfx
meshfx for collision in unity
meshfx measures faults, checks repairs and makes LODs. Build physics shapes in your engine or editor. Hosted meshfx runs are available in the Playground.
Why is my Mesh Collider not working in Unity?
Check that the collider has a mesh assigned, enable Convex if attached to a moving Rigidbody and verify physics layer collisions.
What is a Mesh Collider in Unity?
A Mesh Collider is a Unity physics component that builds a collision shape directly from an assigned mesh asset.
How do I use a collision mesh from a 3D editor in Unity?
Export a simplified mesh from a 3D editor, assign it to the Mesh Collider component's Mesh slot and enable Convex for moving objects.
What does Precompute Collision Geometry do in Unity?
Precompute Collision Geometry builds physics collision data during the project build instead of at runtime, reducing scene load hitches.
How simple should a Unity collision mesh be?
Use Box, Sphere or Capsule colliders whenever possible and keep convex Mesh Colliders under Unity's 255 triangle hull limit.
Explore meshfx outputs
Inspect compiled meshfx outputs and their reports. Hosted meshfx runs are available in the Playground.