I’m generating procedural meshes, storing those meshes in Scriptable Objects, and then assigning them to a mesh collider. However, upon upgrading from 2020 → 2021, I started getting these errors where I assign the Mesh Collider:
This Mesh Collider is attached to GameObject at path 'Prefab Mode in Context/Walkway_Small_Corner' with Mesh 'Walkway_Small_Corner_mesh_fc3f22ce-e547-470e-ab87-5ceb032bd183_0' in Scene 'Walkway_Small_Corner' but doesn't have Read/Write enabled. Only colliders that have default cooking options, are not scaled non-uniformly, and their meshes are not marked dirty can leave this disabled.
The stacktrace comes back to something as simple as:
submesh.MeshCollider.sharedMesh = unityMesh;
Why would this error be occurring? How can I set the read/write flag of a mesh? I can’t find anything about that anywhere. The mesh collider is definitely (1,1,1) scale, I am quite sure the cooking options are default, but I guess their meshes could be dirty as they are being updated in the editor and baked procedurally.
Thanks arfish, I know how to do it in the importer, but I am more looking for how to do it in code as these are procedurally generated meshes, and to actually understand what the heck it is actually complaining about.
I’ve been trying to find a workaround and I learned a few things.
It only happens to me if I try to set meshCollider.sharedMesh to a mesh that has no vertices.
I tried reproducing this in a minimal project, and it only happened if the cooking options are anything other than Everything. I have a much larger project where I’ve verified the cooking options are on Everything, the scale is (1,1,1), and both the sharedMesh and the new Mesh are set to isReadable, and the same problem occurs. It doesn’t occur with every meshCollider with a procedural mesh in that project, but I haven’t yet determined what the difference is when it happens.
Also I was able to verify this happens at runtime, and not just in the editor. Issue still exists in unity 2022
Hey rifewithkaiju, no I hadn’t opened an issue as I didn’t have a good minimal repro, so thanks for looking into that. The zero verts thing is interesting, that’s definitely something to look into for me…
For reference @rifewithkaiju , it looks like preventing my scripts from setting a collider with zero verts did end up resolving the issue here. Would be fantastic if this error message was more explanatory of this possibility though.
Unity 2021.3.6f1
I was getting this error after upgrade to 2021.
In my case i fixed this by disabling collider on game object.
My project is using procedurally generated terrain. I tried to post some simplified codes to fix this problem below.
I was also getting another error when baking collider Physics.BakeMesh . So overall solution for me was
Create new mesh with name,
Disable collider
Set game object active
Set vertices
Recalculate Normals
Bake mesh collider in thread (if i bake mesh before recalculate mesh collider doesnt work.)
Set Mesh Collider
Enable collider
_ChunkMesh= new Mesh() {
name = “ChunkMesh”+ChunkIndex
};
if(collider!=null){
collider.enabled=false;
}
transform.position = new Vector3(Position.x, 0f, Position.y);
gameObject.SetActive( true );
public void AsyncBakeMesh(){
Physics.BakeMesh(_MeshInstanceId, false);
}
I would also like to know a solution to this.
I am getting spammed by these messages in my procedurally generated world, where meshes are created/updated all the time.
I got this problem when replacing my procedural map chunks with new ones (not zero vertices). Fixed it by setting meshCollider.sharedMesh = null whenever I remove mesh data with mesh.Clear().