Name of renderer

I know there is a topic on this but it is still confusing. Why are there squiggly lines under my words. It says something about “hides inherited member”. The game does what it is supposed to do despite this and there are no errors when I run the game. It is just bothersome that I have parts of my code that are not resolving. (I am assuming that Visual Studio does not like my naming convention.)

As usual - confused

1 Like

It says something about “hides inherited member”

  • if you go up the inheritence tree of the MonoBehaiour class you will see a class called Component which has 2 deprecated properties with the same names you have used. These are the ones that are getting “hidden” by the fields you have added to your class. It could be a problem if you wanted to reference those 2 from your code but since you dont it works out ok. Also since they are deprecated unity doesnt want/recommend us using those anyway.

It is just bothersome that I have parts of my code that are not resolving.

  • It is infact resolving to the the fields you have added or it wont have compiled and run , but if it bothers you can just rename to something else .

Okay! Thanks for the explanation. I am just trying to understand what is going on in Unity and Visual Studio. You have made it extremely clear and I appreciate the comments. This is a simple project in the course and I don’t think it will be necessary to change the names to remove the possible conflicts notice in the coding. BUT, for future reference you have helped me a lot in understanding what is going on when you borrow or use a Component’s name for your own use.

Thank you codermonk!

1 Like

Hi Richard,

Add the new keyword in front of the variables to create new variables. That should solve the conflict and remove the warning, and then you’ll be able to name your own variables renderer and rigidbody respectively.


See also:

1 Like

And what is the new keyword? or did you mean to use “new” in front of the variable?

WAIT-HOLD ON!!
I just figured out what you meant and tried it. I typed “new” on the line before each variable and the squiggly line in the code went away. That happened for both variables that I made as new variables. The game works as expected either way but I have no nagging indicator on those variables that something is not as it should be.

I really appreciate the help you and others have offered! :slight_smile:

1 Like

Yea adding new makes the warnings go away as it confirms to the compiler you are knowingly hiding the inherited variable of the same name. The code itself is still going to work the same with or without it though as you have already seen.

1 Like

Oops, I forgot the code formatting. That made my original sentence fairly confusing. I’ve just edited my previous answer but I’m glad you already figured out what I meant. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms