Changing mesh.uv works in editor, but not on Android

Hello,

I’m working on a project where I am trying to programmatically adjust the UVs of meshes in my scene.

The meshes I’m working with represent the floors of the level and the changes to the UVs are to make sure the floor textures are consistently tiled regardless of the floor mesh size.

The changes to the UVs seem to work fine when running the game in the Unity Editor, but when I export a build to an Android device the changes don’t seem to take effect.

The code below is called on Awake()

foreach (var floor in area.FloorSurfaces) {

				MeshFilter meshFilter = floor.GetComponent<MeshFilter> ();

				List<Vector2> uvs = new List<Vector2> ();
				foreach (var vertex in meshFilter.mesh.vertices) {

					if (floor.transform.up.y > .5f) {
						uvs.Add (new Vector2 (vertex.x * (floor.transform.lossyScale.x), vertex.z * (floor.transform.lossyScale.z)));
					} else {
						uvs.Add (new Vector2 (vertex.x * (floor.transform.lossyScale.x), vertex.y * (floor.transform.lossyScale.y)));
					}
				}

				meshFilter.mesh.uv = uvs.ToArray();
			}

77281-unity-editor.png
77280-android.png

The problem wasn’t specific to Android, it was in any build. I had the mesh marked as static and trying to edit the uvs after the game started was throwing errors.

The solution I ended up going with was to create a AssetPostProcessor and handle this in the OnPostprocessModel event, which makes much more sense for what I was trying to do anyway.