Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

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