change the mesh of object during runtime using javascript


how do you change a mesh of an object with javascript during runtime…

it should be as easy as
or gameObject.Find(“myMesh”).MeshFilter.Mesh=“AnotherMesh”;
or gameObject.Find(“myMesh”).Renderer.Mesh=“AnotherMesh”;
you know, something along these lines…

…but its not (by far its not) Every single ‘answer’ I have seen has not worked?
I have tried over 30 of them!

I feel should be astonishingly easy as say hiding an object like…


I want to do this with javascript not c#

any pointers would be great, thanks community!


Here is a bit of example code:

 #pragma strict

 var newMesh : Mesh;

 function Start() {
     var mf : MeshFilter = GameObject.Find("myMesh").GetComponent(MeshFilter);
     if (mf != null) {
         mf.mesh = newMesh;

Note this code assumes that “myMesh” exists and that you are changing and existing mesh. It will fail if “myMesh” does not have a MeshFilter component. It also assumes that your are initializing ‘newMesh’ by dragging and dropping a mesh onto this variable in the inspector.