Cooooding!!

Unity(C#)を使ったゲーム開発関連Tipsなど

Unity2019.2に更新して発生したトラブルとその対処【Unity】

概要

プロジェクトをUnity2019.1.9f1からUnity2019.2.9f1に更新に更新したところ大量のコンパイルエラーが出てしまいました。

Unity2019.2.9f1に更新して発生したエラー

調べてみたところどうやらAssembly Definitionの仕様変更による影響のようだったのでその詳細と対処方法をまとめます。

エラー内容詳細

エラーは以下のようにOdinのクラスや名前空間にアクセスしているところで発生しているようでした。

Unity2019.2.9f1に更新して発生したエラーの発生個所1

The type or namespace name 'Sirenix' could not be found (are you missing a using directive or an assembly reference?)

Unity2019.2.9f1に更新して発生したエラーの発生個所2

The type or namespace name 'ReadOnlyAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ShowInInspectorAttribute' could not be found (are you missing a using directive or an assembly reference?)

原因

このエラーはAssembly Definitionの仕様が変更されたことにより「Test Assemblies」が消えたことと、Unityのアップデート処理でこれらの移行がうまくできなかったのが原因のようです。

おそらく以下の条件を満たしていればOdin以外のdllでも発生するのではないかと思います。

  • Assembly Definitionを使っている
  • Test Assembliesにチェックを入れていた
  • そのAssembly Definition以下のスクリプトコンパイル済みのdllを参照している

対処方法

このエラーは参照関係を正しく設定してあげれば解決します。

Test Assembliesにチェックを入れていたAssembly Definitionは移行後に以下のようになっていると思います。
Unity2019.2.9f1に更新後のAssembly Definitionの設定

問題があるのは「Assembly References」の部分です。参照が足りていないので追加します。今回のケースではOdinのdllを2つ追加しました。
Unity2019.2.9f1に更新後のエラーを修正したAssembly Definitionの設定

(※ もし「Assembly References」の項目が表示されていなければ「Override References」のチェックを入れると表示されます。)

環境

  • Unity2019.1.9f1
  • Unity2019.2.9f1