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