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. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

[SerializeField] warnings

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

  1. Racoon_7


    Nov 11, 2017

    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,
    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


    QA Jesus

    Jun 12, 2013
  3. Racoon_7


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