How can I get rid of COLOR attribute on my vertices?

I am trying to get some GameObjects to dynamically batch. I only want Location, UV, and Normal to be used. Just a basic lit, UV mapped object. My mesh has 266 vertices. I put several in the scene and they will NOT batch. If I lower the vertex count to 225, then it WILL batch. So … I think I have narrowed it down to having a COLOR attribute on my vertices pushing me over the 900 vertex attribute limit. How do I drop that COLOR attribute off my mesh?? If I use certain unlit shaders that don’t use color it WILL batch. I guess I need a basic Diffuse shader that drops that COLOR attribute out so I can batch up to 300 vertex objects? Any help please???

Here is an editor script (untested) that should null out the color array of a mesh.

  • Create a CS script called “MeshColorNull”
  • Insert the code below
  • Put the resulting file in the Assets/Editor file
  • Select the mesh you want to set the color array to null
  • Do: Window/Mesh Color Null

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class MeshColorNull : EditorWindow {
	
	private string error = "";
	
	[MenuItem("Window/Mesh Color Null")]
	public static void ShowWindow() {
		EditorWindow.GetWindow(typeof(MeshColorNull));
	}

	void OnGUI() {
		GUILayout.Label ("Nulls out the color array in the mesh");
		GUILayout.Space(20);

		if (GUILayout.Button ("Null Color")) {
			error = "";
			NullTheColor();
		}
		
		GUILayout.Space(20);
		GUILayout.Label(error);
	}
	
	void NullTheColor() {
		Transform curr = Selection.activeTransform;

		if (curr == null) {
			error = "No appropriate object selected.";
			Debug.Log (error);	
			return;
		}

		MeshFilter mf = curr.GetComponent<MeshFilter>();

		if (mf == null || mf.sharedMesh == null) {
			error = "No mesh on the object.";
			Debug.Log (error);
			return;
		}
		
		mf.sharedMesh.colors = null;
	}
}

I don’t think you can tell Unity not to import colors. I think it will always import it as long as they are available in the file tha you’re importing. Maybe you can export your mesh somehow without colors? For exmaple export into different format (obj)?

Otherwise you need to writer a smarter script which removes color array and merges identical vertices.