Setting the tensor manually

This error has been annoying me for a very long time, and I can not find a proper answer to it. It is the really annoying error:

Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!
UnityEngine.MeshCollider:set_sharedMesh(Mesh)

A lot of people are saying to turn the mesh collider into a box collider, but that is not a possibility here. So, I try and do what it suggests right before the line that is throwing this error.

//This updates the collisionMesh based on the animations and what not
UpdateMesh();
// not sure why this is necessary, but it is
meshCollider.sharedMesh = null;

//The meshRigidBody is the meshCollider.rigidBody
meshRigidBody.inertiaTensor = Vector3.zero;
meshRigidBody.inertiaTensorRotation = Quaternion.identity;
		
// set the collider mesh.
// THIS is the line that is throwing the error.
meshCollider.sharedMesh = Instantiate(collisionMesh) as Mesh;

Yet that does absolutely nothing. How am I suppose to set the tensor manually??? (Note: I don’t even need the physics that is going on with the tensor stuff, but we need a RigidBody)

Have you tried setting the inertia tensor to something other than a zero vector? A zero inertia tensor only makes sense for a kinematic body which is perhaps why Unity is still attempting to calculate it from the volume anyway. You could calculate an approximate inertia tensor by imagining a bounding volume around your mesh and using one of the equations from here → “List_of_moment_of_inertia_tensors”. Note that Unity’s inertia tensor vector is the diagonal elements of the matricies in the given link.

I had a situation where the behavior of plane colliders (only one side collides) was desired on parts of a rigid body which also had other valid colliders. What ended up being effective was disabling the collider behaviours on the prefab, then before the colliders were needed capture the already calculated tensor, cache it, enable the colliders, and then set the values afterwards.

Vector3 planeInertiaTensor = topPlane.rigidbody.inertiaTensor;
Quaternion planeIntertiaTensorRotation = topPlane.rigidbody.inertiaTensorRotation;

foreach (MeshCollider collider in planeColliders)
{
    try
    {
        collider.enabled = true;
    }
    catch { }
    
}

topPlane.rigidbody.inertiaTensor = planeInertiaTensor;
topPlane.rigidbody.inertiaTensorRotation = planeIntertiaTensorRotation;

One thing to note, as soon as the colliders were enabled the error occurs, so a try / catch block was used. Not exactly an elegant solution but this worked for me. Is there a chance setting this tensor is actually working for you and you just need to deal with the exception?