Get child object mesh

Hello!

I’ve got object1 with a variable which holds object2.

I’d like to be able to to take the mesh of object2 and apply it to object1. Object2 has it’s mesh stored in a child.

var object1MeshFilter : MeshFilter = gameObject.GetComponent(MeshFilter);
object1Mesh = object1MeshFilter.mesh;

var object2MeshFilter : MeshFilter = object2.GetComponentInChildren(MeshFilter);
object2Mesh = object2MeshFilter.mesh;

object1Mesh = object2Mesh;

I’m pretty sure where I’m going wrong is actually retrieving the mesh from object2…

The last line is wrong. It should be:

object1MeshFilter.mesh = object2Mesh;