Visual studio warning CS0108 - "...hides inherited member..."

Hi all,

I´m getting this error in Visual Studio: “CS0108: Rocket.rigidbody hides inherited member Component rigidbody. Use the new keyword if hiding was intended”.

I thought maybe I had used a capital letter instead a small, or vice versa, but I haven´t, code looks fine regarding to this. Now I don´t know how to clear this warning. Need some help please!


Welcome to our community! :slight_smile:

Which version of Unity do you use?

Try to rename the variable. In past versions of Unity, there was a “magical” variable named rigidbody. It was deprecated many years ago, but it might be that it is still implemented and causing a conflict.

Alternatively, type new in front of your variable declaration.

Did this help?

See also:

Hi Nina,

And thanks a lot for replying! Unity v.2019.4.9f1 is my version of Unity.

I tried first, as you recommended, to put new in front of Rigidbody rigidbody;
That seemed to help actually. Can you please explain to me why that works?

Thank you!

As aforementioned, there was/is a rigidbody variable in the Unity framework which still seems to be accessible. For this reason, you got that warning message. You didn’t do anything wrong.

With the new keyword, you tell the compiler that you want to create a new variable named rigidbody and that you didn’t make a mistake by declaring an already existing variable again.

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

Privacy & Terms