Hides inherited member

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EmployeeController : MonoBehaviour {

    string name;

    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
       
    }
}

this is whole code, for string name says: hides inherited member use keyword new if hiding was intentional.
Why does it do this, i dont even know what inherited member means here.

thanks

The MonoBehaviour class contains a string member called ‘name’ already which your derived class inherits. It’s telling you this because you’ve declared a member with that same name.

so this is implemented in default MonoBehaviour and i cant use variable name, because i dont have variable name in other scripts

Like the warning says, use the new keyword if you want to hide the base class name member.

new string name;

yeah i know that, fixed it but OCD kind of kicks and knowing i cant use variable “name” makes me uncomfortable,
is there some list of variables i cant use or something? how to enable usage of variable name other than new

Seems that you need to learn about inheritance. There’s a link in my OP for the MonoBehaviour docs, which lists all the members and inherited members. For your OCD you can omit the new keyword and disable the warning using #pragma warning but it would benefit you to learn about inherited members.

1 Like

what you actually mean by OP i checked your profile and there are 2 links, one to your AppyNation webstie where are your games and otheris your page i guess which has your portfolio.

Yes, it’s the list of members of the type you inherited from (members including fields/variables, properties, methods).

In this case MonoBehaviour:

Everything on that page (with exception of the Messages), are members already defined on MonoBehaviour. Avoid defining new members with the same names.

Technically there’s some others that are undocumented, because Unity has obsoleted them. If you are using a full fledge IDE like Visual Studio, you can highlight MonoBehaviour in your code, right click, and select ‘goto definition’. This will bring you to the MonoBehaviour definition, and it’ll list all members, including those obsoleted.

1 Like

Thanks for the list,
Thanks.

Note, the list of members will change if you inherit from a different type in the future. So keep that in mind.

1 Like

If you’re using Visual Studio, let Intellisense do the work for you.

In a function, begin typing “this.na…” and it’ll pop up in intellisense. If it’s there, it’s already in use.

Or put the cursor on “Monobehaviour” and hit F12 to “Go to definition”, and it’ll show you the class members and methods. Also note that “Monobehaviour” itself derives from “Behaviour” which reserves “enabled”, and so on.

1 Like

Original Post.