I’m using the CombineMeshes script from the scripting reference pages…
public class CombineMeshes : MonoBehaviour
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;
transform.GetComponent().mesh = new Mesh();
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…
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.
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?