Unity5 CG Shader get model position.

As described in this question it should be possible to get the world position of the root of a model using the following CG code.

float3 modelPos = mul (float4(0,0,0,1), _Object2World).xyz; // Doesn't work in Unity5

In Unity 4.6 this works, but after debugging it in Unity 5.0 it no longer seems to do it, and the resulting values for modelPos are (0,0,0).


  1. Is this a bug with Unity5? I have noticed other shader differences since D3D9 shader compiler was switched from Cg 2.2 to HLSL

  2. Is there another method of deriving a unique float3 value based on the objects world position, without passing it in from CPU code as a property?

It seems the cuplrit was dynamic batching of the objects I was testing.

A single object worked fine, but in the test scene I would copy a lot of objects around. You can mark a shader to not dynamically batch by adding.

"DisableBatching" = "True" 

To the tags of the shader.