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?
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.
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.