Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MeshFilter.mesh

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var mesh: Mesh;
public Mesh mesh;
public mesh as Mesh

Description

Returns the instantiated Mesh assigned to the mesh filter.

If no mesh is assigned to the mesh filter a new mesh will be created and assigned.

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.

By using mesh property you can modify the mesh for a single object only. The other objects that used the same mesh will not be modified.

	// Distortionates the mesh vertically.

function Update () { // Get instantiated mesh var mesh : Mesh = GetComponent(MeshFilter).mesh; // Randomly change vertices var vertices : Vector3[] = mesh.vertices; for (var p : int = 0; p < vertices.Length; p++) { vertices[p] += Vector3(0, Random.Range(-0.3, 0.3), 0); } mesh.vertices = vertices; mesh.RecalculateNormals(); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = mesh.vertices;
        int p = 0;
        while (p < vertices.Length) {
            vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0);
            p++;
        }
        mesh.vertices = vertices;
        mesh.RecalculateNormals();
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Update() as void:
		mesh as Mesh = GetComponent[of MeshFilter]().mesh
		vertices as (Vector3) = mesh.vertices
		p as int = 0
		while p < vertices.Length:
			vertices[p] += Vector3(0, Random.Range(-0.3F, 0.3F), 0)
			p++
		mesh.vertices = vertices
		mesh.RecalculateNormals()

See Also: Mesh class.