Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Different Script Warnings with Certain Windows Builds?

Discussion in 'Windows' started by SonicBloomEric, Feb 3, 2016.

  1. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    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?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,478
    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:

    Code (csharp):
    1.  
    2. class MyClass
    3. {
    4.    private object myField;
    5.  
    6.    public object GetField { get { return myField; } }
    7. }
    This doesn't:

    Code (csharp):
    1.  
    2. class MyClass
    3. {
    4.    private object myField = null;
    5.  
    6.    public object GetField { get { return myField; } }
    7. }
    8.  
     
  3. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    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 ;) ).

    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 :)

    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?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,478
    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.
     
  5. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    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 :)

    Nice! I'd love to hear what you dig up, if anything!
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,478
  7. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,081
    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".
     
    Last edited: Feb 4, 2016