Does it @*#! hide an inherited member, or not?!

I’m trying to squash warnings in my project. Most of them are something like this:

I see similar warnings on animation and camera. OK, sez I, I can add the new keyword. So I do, and for a while all is fine. But then when I build (for Android), I get:

What?! It literally just told me the exact opposite. (And same happens for the other warnings I fixed with new).

It appears to be some difference between the automatic compiling that happens whenever the editor feels like it, and the compiling that happens when making a build. (I don’t know if it affects only Android builds or if other platforms show the same thing.)

This is frustrating my warning-squashing goals. I know I could just use a pragma to disable that warning, but I’d rather treat the cause, not the symptom. But these warnings can’t both be right. What’s going on here, and is there any way (short of pragma warning disable, or changing my property names to something less ideal) to make it stop?

3 Likes

Any chance there are compiler directives changing the visibility of methods based on the targeted platform?

If so, another hacky approach would be to use the same strategy in reverse …

#if !Unity_Android new #endif

Personally, I think I’d just change the method names.

1 Like

Also … this seems like a particularly confused property.

The documentation says it was removed and you should use GetComponent instead, so maybe that has something to do with it.

The renderer property is here:

Though I can’t prove it, I suspect this file is not included when you compile for runtime. That means you are hiding during build time and not hiding during runtime.

I’m not sure there are any “good” fixes for this. I’d still favour changing your property name.

They might also conditionally exclude files based on whether the project is using them or not. So if OP is using new, none of these are actually in use and then new becomes unnecessary.

Yeah, I’ll second this… ever since renderer was deprecated circa 2014 or 2015 I’ve always just used rndrr in my code and found it far more greppable. :slight_smile:

1 Like

I use “ren” due to this personally lol

I have developed a potentially bad habit of turning off the warnings due to these things.

Well, of course I could rename the properties… but I prefer “renderer” to “ren” or “rndrr” (and having to come up with similarly hacky names — no offense! — for things like camera and collider). Our coding standard is to call a thing what it is, unless there is good reason to call it something else. If a script needs a reference to a renderer because its job is to test whether that renderer is in the viewing frustum, there’s no better name for that reference than “renderer”.

So, yeah, I guess I can just use pragma warning disable. But ye golly this is an annoying behavior we have to work around — literally warned if you do, and warned if you don’t.

3 Likes