Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

Graphics.DrawMesh

static function DrawMesh(mesh: Mesh, position: Vector3, rotation: Quaternion, material: Material, layer: int, camera: Camera = null, submeshIndex: int = 0, properties: MaterialPropertyBlock = null): void;
static function DrawMesh(mesh: Mesh, position: Vector3, rotation: Quaternion, material: Material, layer: int, camera: Camera, submeshIndex: int, properties: MaterialPropertyBlock, castShadows: bool, receiveShadows: bool): void;
static function DrawMesh(mesh: Mesh, matrix: Matrix4x4, material: Material, layer: int, camera: Camera = null, submeshIndex: int = 0, properties: MaterialPropertyBlock = null): void;
static function DrawMesh(mesh: Mesh, matrix: Matrix4x4, material: Material, layer: int, camera: Camera, submeshIndex: int, properties: MaterialPropertyBlock, castShadows: bool, receiveShadows: bool): void;

Parameters

meshThe Mesh to draw.
positionPosition of the mesh.
rotationRotation of the mesh.
matrixTransformation matrix of the mesh (combines position, rotation and other transformations).
material Material to use.
layer Layer to use.
cameraIf null (default), the mesh will be drawn in all cameras. Otherwise it will be rendered in the given camera only.
submeshIndexWhich subset of the mesh to draw. This applies only to meshes that are composed of several materials.
propertiesAdditional material properties to apply onto material just before this mesh will be drawn. See MaterialPropertyBlock.
castShadowsShould the mesh cast shadows?
receiveShadowsShould the mesh receive shadows?

Description

Draw a mesh.

DrawMesh draws a mesh for one frame. The mesh will be affected by the lights, can cast and receive shadows and be affected by Projectors - just like it was part of some game object. It can be drawn for all cameras or just for some specific camera.

Use DrawMesh in situations where you want to draw large amount of meshes, but don't want the overhead of creating and managing game objects. Note that DrawMesh does not draw the mesh immediately; it merely "submits" it for rendering. The mesh will be rendered as part of normal rendering process. If you want to draw a mesh immediately, use Graphics.DrawMeshNow.

Because DrawMesh does not draw mesh immediately, modifying material properties between calls to this function won't make the meshes pick up them. If you want to draw series of meshes with the same material, but slightly different properties (e.g. change color of each mesh), use MaterialPropertyBlock parameter.

See Also: MaterialPropertyBlock.

	// Draws aMesh with aMaterial at (0,0,0) with no rotation for one frame

var aMesh : Mesh; var aMaterial : Material;

function Update() { Graphics.DrawMesh(aMesh, Vector3.zero, Quaternion.identity, aMaterial, 0); }