- Home /
How to disable SerializeField attribute related warnings/proposals from MonoDevelop?
I've been using MonoDevelop for quite some time now and am now at a point where I'd like to know how to remove the following things from MonoDevelop explicitly for Unity:
Variables attributed with
[SerializeField]
are mostly getting set via inspector unless you know the default shouldn't be 0, then you set a default value. MonoDevelop complains with CS0649, a value never been assigned to. How do you disable this?The same reason results in the suggestion to make the variable a constant, because the interpreter doesn't know about the underlying serialization process. How to disable that?
Answer by FlaSh-G · Jun 29, 2017 at 09:54 PM
You can disable warnings in C# like this:
#pragma warning disable 649
You can put them at the top of the file, for example.
Edit: For a global solution, you can add compiler instructions.
Add a text file named mcs.rsp (Mono-CSharp [compiler].ReSPonse [file]).
Add this to the file:
-nowarn:649
The nowarn flag works just as the #pragma, with a comma seperated list of warning numbers to ignore.
Another edit: I'd recommend thinking twice before globally disabling these warnings though. They exist for a reason and it might be detrimental to ignore them in all potential situations rather than disabling them deliberately on a case-by-case basis.
Yet another edit: Instead of disabling that warning, I'd recommend using = default
on your fields. Like this:
[SerializeField]
private int number = default;
Also, note Unity's compiler has slowly gotten updated to allow Unity to suppress the warning automatically for serialized fields, and in some feature update, this won't be necessary at all anymore.
I'm looking for global solutions, because this applies for unity in total.
Nice one. Do you have a suggesting for the const suggestion in cases where the SerializeField attribute is set?
If it has a warning number, add it to the list. If not, I have no clue.
Your answer
