Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. We are looking for feedback on the naming of a new user research platform that we are working on.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[SerializeField] warnings

Discussion in '2018.3 Beta' started by Racoon_7, Sep 25, 2018.

  1. Racoon_7

    Racoon_7

    Joined:
    Nov 11, 2017
    Posts:
    11
    Hi,

    ever since I switched to the new beta (which, I believe, comes with a new compiler), my console log is getting flooded by: Warning CS0649: Field '***' is never assigned to, and will always have its default value null

    The source of these warnings is essentially every MonoBehaviour which uses the SerializeField attribute for its fields to make them editable through the Inspector.
    This is nothing new, Visual Studio kept complaining about this as far as I can remember,
    Cursors.png
    but never before did these warnings appear inside the Editor; so they cannot be simply overlooked now because they spam the Console and the actual valid warnings are scattered in between.

    The solutions to this I thought of:

    a) Forget [SerializeField] and make everything 'public'
    • I wouldn't really want to do this because it goes against the OOP principle of encapsulation and makes the code less manageable and more prone to errors
    b) #pragma warning disable 649
    • That would have to be added to every single cs file.
    c) "JetBrains.Annotations.UsedImplicitly" attribute
    • Silences the error in Visual Studio, but not in the Console
    d) csc.rsp file with '-nowarn:0649'
    • This is what I am using right now. Still, it may silence legitimate 'unassigned field' warnings.

    Is this a bug which can be fixed, or is there a better way to deal with this?
     
    jhocking-bundlar likes this.
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,313
  3. Racoon_7

    Racoon_7

    Joined:
    Nov 11, 2017
    Posts:
    11
    Thank you. I wasn't able to find the relevant thread yesterday. I'll continue there.
     
unityunity