- Home /
No 'Renderer' attached to the "Main Camera"
My Error Message I get at any frame (cause its in LateUpdate):
"MissingComponentException: There is no 'Renderer' attached to the "Main Camera" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "Main Camera". Or your script needs to check if the component is attached before using it."
I call this function in LateUpdate(): CharacterFade();
void CharacterFade() {
if (RPG_Animation.instance == null)
return;
if (distance < firstPersonThreshold)
RPG_Animation.instance.renderer.enabled = false;
else if (distance < characterFadeThreshold) {
RPG_Animation.instance.renderer.enabled = true;
float characterAlpha = 1 - (characterFadeThreshold - distance) / (characterFadeThreshold - firstPersonThreshold);
if (RPG_Animation.instance.renderer.material.color.a != characterAlpha)
RPG_Animation.instance.renderer.material.color = new Color(RPG_Animation.instance.renderer.material.color.r, RPG_Animation.instance.renderer.material.color.g, RPG_Animation.instance.renderer.material.color.b, characterAlpha);
}
else {
RPG_Animation.instance.renderer.enabled = true;
if (RPG_Animation.instance.renderer.material.color.a != 1)
RPG_Animation.instance.renderer.material.color = new Color(RPG_Animation.instance.renderer.material.color.r, RPG_Animation.instance.renderer.material.color.g, RPG_Animation.instance.renderer.material.color.b, 1);
}
}
What am I doing wrong and how do I fix it?
It seems your RPG_Animation script is attached to the $$anonymous$$ain Camera.
Yes you are right, I had accidentally attached the RPG_Animation script to the wrong GameObject. It was of course supposed to be attached to my PlayerCharacter. I still get this error message:
$$anonymous$$issingComponentException: There is no 'Renderer' attached to the "PlayerCharacter" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "PlayerCharacter". Or your script needs to check if the component is attached before using it.
But the error still leads me to the code I posted above.
And your player has a renderer or what about your RPG_Animation, does it inherit from $$anonymous$$onoBehaviour?
Yes my RPG_Animation class inherits from $$anonymous$$onoBehaviour.
It was indeed the missing Renderer on my PlayerCharacter... just like the Error$$anonymous$$essage said. Thank you very much, I was so confused right now.
Ill better go to bed now.