Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Discussion FileSystemWatcher runs too slow on Unity Editor

Discussion in 'Editor & General Support' started by NGC6543, Jul 14, 2022.

  1. NGC6543


    Jun 3, 2015
    Hi, I'm trying to create my own file change monitoring system using
    But the watcher performance is too bad for practical use.

    • I have additional codegen / datagen apps outside the Unity Editor.
    • When they run, they write a lot of files inside Unity Assets folder.
    • If Unity 'Auto Refresh' option is enabled, the two processes can interfere and unwanted result may occur.
      • So I need to disable the 'Auto Refresh' option, and refresh Asset import manually.(
    • I want to notify users with GUI when file change is detected.
    • I decided to make a watcher using
      • A class with
        creates and holds the watcher instance.
    • The watcher class runs fine when built as a console app.
      • File change events are picked up immediately.
    • The same class runs extremely slow when run in Unity Editor.
      • It took more than 5 seconds to get the change event.
    • Create Watcher instance on a background thread(
      • Still too slow.
      • According to the sourcecode, FileSystemWatcher uses Threadpool internally. So the watcher is running on a background thread already.
    • I want to know why the watcher run slow when in Unity Editor. What makes it differ from console?
    • What is the proper way to implement my own file watcher in Unity?