Where is the Renderer component ? It's not the in unity editor menu Component

tmpobj.name = "Plane"; tmpobj.GetComponent<Renderer>().material.color = new Color(0.9490f, 0.8901f, 0.7686f, 0);

I need to add to the script a component called Renderer but i can’t find it in the Component menu.
Not in Component > Rendering and not in other places.

The complete script:

using UnityEngine;
using System.Collections;

public class DragAndDrop : MonoBehaviour
{

    void Start()
    {
        GameObject tmpobj = new GameObject(); MeshFilter mf = tmpobj.AddComponent<MeshFilter>();

        tmpobj.name = "Plane"; tmpobj.GetComponent<Renderer>().material.color = new Color(0.9490f, 0.8901f, 0.7686f, 0);

        Vector3[] verts = new Vector3[4]; Vector2[] uv = new Vector2[4]; Vector3[] normals = new Vector3[4]; int[] tri = new int[6];

        verts[0] = new Vector3(10f, 10f, 10f); verts[1] = new Vector3(10f, 10f, 10f); verts[2] = new Vector3(10f, 10f, 10f); verts[3] = new Vector3(10f, 10f, 10f);

        normals[0] = new Vector3(10f, 10f, 10f); normals[1] = new Vector3(10f, 10f, 10f); normals[2] = new Vector3(10f, 10f, 10f); normals[3] = new Vector3(10f, 10f, 10f);

        uv[0] = new Vector2(10f, 10f); uv[1] = new Vector2(10f, 10f); uv[2] = new Vector2(10f, 10f); uv[3] = new Vector2(10f, 10f);

        tri[0] = 2; tri[1] = 0; tri[2] = 3;

        tri[3] = 1; tri[4] = 0; tri[5] = 2;

        Mesh mesh = new Mesh(); mesh.name = "Plane"; mesh.vertices = verts; mesh.triangles = tri; mesh.uv = uv; mesh.normals = normals; mf.mesh = mesh;
    }
}

You need to add the MeshRenderer component, there is no component called just Renderer (though that is the base class for all other renderers.

1 Like

The problem is that the object Cube that the script is attached to it have already Mesh Renderer component and still when i’m running the game i’m getting the exception:

MissingComponentException: There is no ‘Renderer’ attached to the “Plane” game object, but a script is trying to access it.
You probably need to add a Renderer to the game object “Plane”. Or your script needs to check if the component is attached before using it

And i can’t add another Mesh Renderer to the Cube.

A screenshot:

Well, you need to add a MeshRenderer to the plane as that is the object you try to get the renderer from:

GameObject tmpobj = new GameObject(); MeshFilter mf = tmpobj.AddComponent<MeshFilter>();
        tmpobj.name = "Plane"; tmpobj.GetComponent<Renderer>().material.color = new Color(0.9490f, 0.8901f, 0.7686f, 0);
1 Like