I’m using the CombineMeshes script from the scripting reference pages…
public class CombineMeshes : MonoBehaviour
{
void Start()
{
Component meshFilters = GetComponentsInChildren();
CombineInstance combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length)
{
combine_.mesh = meshFilters*.GetComponent<MeshFilter>().sharedMesh;*_
combine_.transform = meshFilters*.transform.localToWorldMatrix;
//combine.transform = meshFilters.transform.worldToLocalMatrix;_
_meshFilters.gameObject.active = false;
i++;
}
transform.GetComponent().mesh = new Mesh();
transform.GetComponent().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
}
…and all is fine and dandy except for this really odd problem.
I have two GameObjects; one with CombineMeshes and another with a model called MeshInstance. MeshInstance sits inside CombineMeshes as a child object.
If I put CombineMeshes at a position of 0, 0, 0 and throw all my meshes inside it, all the instance meshes will be correctly positioned when the game is run. As you would expect…
However.
When I move CombineMeshes to anything other than 0, 0, 0 and run the game, all the instanced meshes are offset and I have no idea why. Take a look at this pic.
![alt text][1]
In this example, CombineMeshes is now at 32, 0, 0 and MeshInstance is at -32, 0, 0. When I run the game, MeshInstance is moved x axis by 32 units (to the right).
Why does it do this?
[1]: http://dl.dropbox.com/u/1008157/Misc/transform-problems.png*_