Different Script Warnings with Certain Windows Builds?

We’re receiving reports that some of our scripts are outputting warnings when built for certain Windows platforms. Specifically, we just received a report of the following warning:

We are entirely aware of this and the field itself is marked as [SerializeField] with the intent that it’s hooked up in the inspector.

The thing is that we do not see this warning in the Unity Editor on Mac or even with normal Windows builds. Our users report this when compiling for Win RT platforms so we suspect that the warning is possibly comming from the .NET compilers(?).

Is this intentional? An oversight? A limitation of the system?

Hi,

that’s the way Microsoft’s C# compiler (Roslyn) rolls. It’s nothing that we have control over. However, it’s pretty easy to work around.

This triggers the warning:

class MyClass
{
   private object myField;

   public object GetField { get { return myField; } }
}

This doesn’t:

class MyClass
{
   private object myField = null;

   public object GetField { get { return myField; } }
}

Is that really true, though? The Microsoft C# compiler has support for the /nowarn option just like Mono (actually, Mono supports it for compatibility with the C# compiler). It even looks like you could set this in the Visual Studio Solutions that get generated.

I suspect this is already happening with other warnings that are on by default with the mono compilation system. Indeed, it looks like the generated project files are set up to ignore warning 0169 at the very least:

I haven’t seen an equivalent setting for 0649. A quick test, however, shows that this warning is suppressed if the field is marked as [SerializeField]. My guess is that you guys modified your Mono compilers internally to suppress that warning if [SerializeField] is set (or some other kind of magic :wink: ).

As far as the fix goes, I’m totally aware of that. It’s just that we don’t normally do development on those platforms and the current MonoDevelop-based builds (whether compiled in MonoDevelop or Unity) do not show those warnings. I’m merely looking for parity :slight_smile:

Another option in the quest for parity here would be the ability to put Unity’s Mono compilers into .NET-compatibility mode to identify these issues. Is there something around like this, perhaps?

Well, you can always add a response file to Unity project to disable that warning if you want.

I’ll dig deeper to see whether we had indeed hacked up our mono C# compilers.

I mean, it’s only an issue for our Windows users. I know how to stop it from happening, it’s just that we don’t get the warnings in other mainline platforms. And it’s a pretty simple mistake to make :slight_smile:

Nice! I’d love to hear what you dig up, if anything!

Well, I did find why Mono C# compiler doesn’t print the warning:

https://github.com/Unity-Technologies/mono/blob/unity-staging/mcs/mcs/class.cs#L2130

I don’t think there is a way to force mono compiler into a mode so it would output the warning.

You could actually use Roslyn on Mac to test-compile your scripts to see whether there aren’t any warnings.

I see. It looks like this is still the case in the latest mono version as well. And it appears that it’s not just [SerializeField] but any Field Attribute that will stop this warning in Mono compilers…

Looks like we might need to add a step for that or something in the build system. Boo.

Thanks for the info on this! Looks like it’s just one of those things we can chalk up to “Compiler differences”.