LoginSignup
46
19

More than 5 years have passed since last update.

[SerializeField] 属性をつけていると、CS0649警告が出るようになった。消したい。

Last updated at Posted at 2019-02-28
  • 環境 2018.3.5f1

Unity 2018.3 にアップグレードしたら、
.NET 3.5 (deprecated) ということで、.NET 4.x にしました。

そしたら、とてもたくさんの・・・
100個以上たくさんの、、Warning が表示される
xxx.cs(23,37): warning CS0649: Field 'xxx.obj' is never assigned to, and will always have its default value null

邪魔すぎるので、消す方法を調べる。

Warning CS0649 not suppressed properly when field is marked as [SerializeField] - Unity Forum

before [SerializeField] GameObject obj;

方法1 [SerializeField]を忘れて、すべてを 'public'にする

public GameObject obj;

方法2 #pragma warning disable 649

#pragma warning disable 649
[SerializeField] GameObject obj;
#pragma warning restore 649

方法3 '-nowarn:0649'を含むcsc.rspファイル

Assets直下に、「csc.rsp」というファイルを作成する

csc.rsp
-nowarn:0649

方法4 デフォルト値で初期化する

[SerializeField] GameObject obj = default;

検索:\[SerializeField\]([^=]+?);
置換:[SerializeField]$1 = default;

Visual Studio for Mac だと、
Command + Shift + F キー
[フォルダーを指定して検索]/[フォルダーを指定して置換]

スクリーンショット

方法1だけは無いなと思うし、個人的には方法4が
この中ではお気に入りです。

おわり

46
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
19