DetectDynamicBatching

Author: Karel Crombecq (Sileni Studios)

Description
Adding this script to a GameObject in your world will overrule all shaders in your scene, and will instead render all objects that are not dynamically batched color-inverted. This is very useful to find issues with your batching, and can greatly help you optimize your rendering.

This check works because apparently, objects that are dynamically batched have their _Object2World transformation matrix, which is only available in the shader, set to the identity matrix, even though Transform.localToWorldMatrix still points to the original, proper matrix. This is probably because the dynamic batching happens at a layer below the script level, where all meshes are combined in one single mesh positioned in the origin of the scene. This is not a 100% accurate check, as objects positioned in the origin initially will falsely be flagged, but it's the best and only method of detecting dynamic batching on a per-object basis that I know of.

Usage
First: make sure the shader is in a Resources folder in your Assets library - otherwise the script won't be able to find it! Drop the DynamicBatchingDetector.cs script on any object in your scene. This script will simply overrule your shaders with the dynamic batching detection shader.