Thread Marshalling

How background watcher events are safely sent to Unity’s main thread to prevent editor crashes.


The Threading Problem

FileSystemWatcher events execute on a background system worker thread. Calling Unity Editor APIs (such as AssetDatabase.ImportAsset or EditorUtility.SetDirty) from a background thread is strictly forbidden by Unity and throws immediate exceptions or crashes the editor.


The Marshalling Solution

  1. Queue Event: When a file modification is caught on the worker thread, DataLoom Pro queues the path in a thread-safe list.
  2. Main Thread Tick: The watch service hooks into EditorApplication.update.
  3. Process Queue: On the next editor update frame, Unity’s main thread reads the queued path and executes the import pipeline safely.

This site uses Just the Docs, a documentation theme for Jekyll.