Not allowed to access vertices on mesh ??

I’m having a script the split a mesh into seperate triangles. That script works fine for default object like cube, sphere, capsule etc but not on others. While runnig it gives “Not allowed to access vertices on mesh” exception. Does anyone know about it , why this is happening ?? Here is the script…

// C#
// SplitMeshIntoTriangles.cs
using UnityEngine;
using System.Collections;

public class SplitMeshIntoTriangles : MonoBehaviour
{
	void Start()
	{
		StartCoroutine(SplitMesh());
	}

	IEnumerator SplitMesh ()
	{
		MeshFilter MF = GetComponent<MeshFilter>();
		MeshRenderer MR = GetComponent<MeshRenderer>();
		Mesh M = MF.mesh;
		Vector3[] verts = M.vertices;
		Vector3[] normals = M.normals;
		Vector2[] uvs = M.uv;
		for (int submesh = 0; submesh < M.subMeshCount; submesh++)
		{
			int[] indices = M.GetTriangles(submesh);
			for (int i = 0; i < indices.Length; i += 3)
			{
				Vector3[] newVerts = new Vector3[3];
				Vector3[] newNormals = new Vector3[3];
				Vector2[] newUvs = new Vector2[3];
				for (int n = 0; n < 3; n++)
				{
					int index = indices[i + n];
					newVerts[n] = verts[index];
					newUvs[n] = uvs[index];
					newNormals[n] = normals[index];
				}
				Mesh mesh = new Mesh();
				mesh.vertices = newVerts;
				mesh.normals = newNormals;
				mesh.uv = newUvs;
				
				mesh.triangles = new int[] { 0, 1, 2, 2, 1, 0 };
				
				GameObject GO = new GameObject("Triangle " + (i / 3));
				GO.transform.position = transform.position;
				GO.transform.rotation = transform.rotation;
				GO.AddComponent<MeshRenderer>().material = MR.materials[submesh];
				GO.AddComponent<MeshFilter>().mesh = mesh;
				GO.AddComponent<BoxCollider>();
				GO.AddComponent<Rigidbody>().AddExplosionForce(100, transform.position, 30);
				
				Destroy(GO, 5 + Random.Range(0.0f, 5.0f));
			}
		}
		MR.enabled = false;
		
		//Time.timeScale = 0.2f;
		yield return new WaitForSeconds(0.8f);
		//Time.timeScale = 1.0f;
		Destroy(gameObject);
	}

	void OnMouseDown()
	{
		StartCoroutine(SplitMesh());
	}
}

The mesh must have “read\write enabled” option set in Inspector like Ashish Dwivedi suggested and this is the right answer.
Making the object static has nothing in common with this error.

If an object is marked as static it is not allowed to access its vertices.

Well, no, thats wrong. Static meshes are static and cannot be modified, thats why you’re getting the error - read/write doesn’t matter at all.

I can Confirm that i cannot read mesh vertices for meshes marked with static.

However, when switching to a WebGL build i do not have this error, which caused some confusion.