There is no renderer attached to the game object
I'm getting this error when trying the instantiate a prefab that has the mesh render in the child object.
ie. I imported a Blender model which created the fbx importer. I created a prefab and dropped the fbx importer into it.
The prefab draws ok on it's own if I drag it onto the scene but the error occurs (and other strange behaviour) when I try to instnatiate it.
Show us your code. Almost certainly you are using renderer
on the wrong object.
Answer by Blinksdope1 · Aug 11, 2017 at 06:49 AM
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ObjectColor : MonoBehaviour { public Color changedColor = Color.white; public Color originalColor = Color.white;
void Awake()
{
originalColor = this.GetComponent<Renderer>().material.color;
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.G)) {
this.GetComponent<Renderer>().material.color = changedColor;
}
else if (Input.GetKeyUp (KeyCode.G))
{
this.GetComponent<Renderer>().material.color = originalColor;
}
}
}
Answer by Dreamora · Jun 27, 2011 at 12:41 AM
Create a prefab and assign it and ensure to apply the changes + save scene so the prefab changes really take place
if you instantiate only a mesh you have to provide the full game object with all components too, a prefab takes care of that for you
Saving the scene will make no difference to the execution of the game.
Answer by Skuzzbag · Jun 27, 2011 at 05:56 AM
I created a mesh renderer for the prefab and it fixed the problem
Answer by shinriyo_twitter · Aug 12, 2011 at 09:22 AM
I met same problem too. I attached a "mesh renderer" to the "prefab". but, I couldn't fix. how did you do another?
Answer by shinriyo_twitter · Aug 12, 2011 at 10:32 AM
I had xxxxing mistake I attached non-related gameobject.. I resolved.