- Home /
Copying a mesh filter component through script.
I am currently working on creating a dummy clone of objects when they are hit. To do this I have created a simple prefab that is only a GameObject with a mesh renderer and mesh filter. I am currently stuck on copying the target's renderer and mesh to this newly instantiated prefab (I will be editing the mesh so I cannot use shared mesh for this case.)
(MeshFilter)(projDecal.GetComponent("MeshFilter")).mesh = mf.mesh;
In an attempt to copy the mesh itself I have tried to instantiate a new meshfilter.mesh and set it, however it appears you cannot change a meshfilter.mesh through script this way.
It appears I can do it as
$$anonymous$$esh decal$$anonymous$$esh = $$anonymous$$esh.Instantiate(mf.mesh) as $$anonymous$$esh;
$$anonymous$$eshFilter mf2 = ($$anonymous$$eshFilter)(projDecal.GetComponent("$$anonymous$$eshFilter")); mf2.mesh = decal$$anonymous$$esh;
It was just breaking while it was a single line for some reason.