I have a MeshFilter attached to a RigidBody with a MeshCollider, and I declare:
Mesh mesh = myObject.GetComponent< MeshFilter>().mesh;
MeshCollider meshCollider = myObject.GetComponent< MeshCollider>();
I update the mesh vertices (from an array called “vertices”) and attempt to update the MeshCollider accordingly:
meshCollider.sharedMesh = null;mesh.vertices = vertices;
meshCollider.sharedMesh = mesh;
When running the game I get the following error upon creation of myObject:
Cooking::cookConvexMesh: user-provided convex mesh descriptor is invalid!
UnityEngine.MeshCollider:set_sharedMesh(Mesh)
I’ve noticed that when I remove the line that turns the sharedMesh into null the error is gone but the MeshCollider won’t update.
Did anyone run into such an error? If so, what am I doing wrong?
Thanks.