Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


MeshRenderer

Renders the mesh from the MeshFilter component on the same GameObject.
Read time 9 minutesLast updated 5 days ago

Definition

public class MeshRenderer : Renderer

Remarks

This component requires a MeshFilter to be attached to the same GameObject. When the component is active, it renders the Mesh specified in the MeshFilter, including any submeshes.
You can disable the MeshRenderer to make the GameObject invisible.
To render deformable meshes, use the SkinnedMeshRenderer component instead.
Additional Resources: MeshFilter, Mesh.
The following code sample creates 10 randomly-colored renderers at random positions in the scene. To use it, attach it to a GameObject and run the project.

Examples

using UnityEngine;public class PlaceRandomCubes : MonoBehaviour{ void Start() { Mesh cubeMesh = Resources.GetBuiltinResource<Mesh>("Cube.fbx"); for (int i = 0; i < 10; i++) { // Create a GameObject at a random position GameObject go = new GameObject(); go.transform.position = Random.insideUnitSphere * 10; // Add a MeshFilter to supply the mesh data MeshFilter filter = go.AddComponent<MeshFilter>(); filter.sharedMesh = cubeMesh; // Add a MeshRenderer to render the mesh, and assign a random color MeshRenderer meshRenderer = go.AddComponent<MeshRenderer>(); meshRenderer.material.color = Random.ColorHSV(); } }}

Properties

Property

Description

additionalVertexStreamsVertex attributes in this mesh will override or add attributes of the primary mesh in the MeshRenderer.
enlightenVertexStreamVertex attributes that override the primary mesh when the MeshRenderer uses lightmaps in the Realtime Global Illumination system.
globalIlluminationMeshLodMesh LOD to use for Global Illumination.
receiveGIDetermines how the object will receive global illumination. (Editor only)
scaleInLightmapSpecifies the relative lightmap resolution of this object. (Editor only)
stitchLightmapSeamsWhen enabled, seams in baked lightmaps will get smoothed. (Editor only)
subMeshStartIndexIndex of the first sub-mesh to use from the Mesh associated with this MeshRenderer (Read Only).

Methods

Method

Description

GetShaderUserValueReturns the custom value assigned to this renderer.
SetShaderUserValueAssign a custom value to this renderer.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.