0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityにてFileSystemWatcherを使用すると「NotImplementedException」で動かないときの対処法

Last updated at Posted at 2020-05-12

はじめに

Unityにてファイルの作成・更新を監視した処理を実装していました。
実装にあたり「FileSystemWatcher」クラスを使用していたのですが、Editorでは問題なく動作していたにもかかわらず、Build Runを行うと、動作しないという現象に遭遇して、対処したのでまとめました

TL;DR

Api Compatibility Levelを「.NET 4.x」に変更すればOKです

環境

Unityのバージョン : 2018.4.21f1

現状の把握

  • 実行時のログを確認します。ログは以下に出力されています

    • C:/Users/【user name】/AppData/LocalLow/【company name】/【product name】
      • user name, company name, product nameはプロジェクトの設定に依存するので、各自の環境で読み替えてみてください
  • FileSystemWatcherが動作しないとき、以下のようにログに出力されていました

output_log.txt
UnloadTime: 1.114600 ms
NotImplementedException: The method or operation is not implemented.
  at System.IO.FileSystemWatcher..ctor () [0x00006] in <0813754e7cfa415ebfedff172c2dd6e0>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileSystemWatcher..ctor()
  at FileManager.Start () [0x00011] in <e475f99b7ae14fec98b1a675e6f35500>:0 

対処法

  1. File→Build Settingsの順でBuild Settingsを表示します
  2. 左下のPlayer Settingsボタンをクリックします
  3. Inspector上にPlayer Settingsが表示されますので、下にスクロールして、Other Player Settingsを展開します
  4. Api Compatibility Levelを「.NET 4.x」に変更(以下参照)し保存します
img1.png

まとめ

FileSystemWatcherが動かなくてお困りの方は参考にしてみてください

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?