Error: warning CS0108: `Tile.renderer' hides inherited member

Okay, so here’s the deal…

I understand that a lot of people and going to view this thinking it’s a total newbie question and fair enough, I’m not exactly and advanced programmer but this issue has me at my wits end…

I’ve declared a public Renderer Object in my script to be set in the inspect. The issue is that when it’s called unity spawns this annoying little warning “Assets/Tile.cs(11,25): warning CS0108: Tile.renderer' hides inherited member UnityEngine.Component.renderer’. Use the new keyword if hiding was intended” The worse thing is, read the error and tried to remedy the problem using the new keyword like so…:

Renderer renderer = new Renderer;

and yet the warning is still their. I really don’t know how to solve this. Somebody please help.

1 Like

The problem is that you’re using “renderer” as your object reference, but there’s already a Unity-based “renderer” member associated with your instance. Just choose another name.

11 Likes

Or use the new keyword, like it tells you to, although I only recommend doing that when you’re storing a reference to the component that Unity’s builtin variable would be returning, which you’re not doing here.

What you showed above, with new, is not what it’s suggesting. What it’s telling you you could do, is this:

new Renderer renderer = GetComponent<Renderer>();

I frequently use this, for example, for performance:

[HideInInspector][SerializeField] new Renderer renderer;

// Reset gets called when you attach the script,
// but I call my Reset functions from a master menu item
// for which I use a keyboard shortcut.
// I set it up in System Preferences, 
// so all my projects use the same key combo.
void Reset () {	
	renderer = GetComponent<MeshRenderer>();
}
4 Likes

Thanks :smile: This warning was driving me insane :smile: