I have a Unity Program that at initialisation loads multiple Gameobjects in the scenes. The Objects where loaded from a file.
I have created a FileWatcher that notifies when a file has changed. Now I like to update my gameobjects with the content of the updated file
public class ProductFolderWatcher : MonoBehaviour {
// Use this for initialization
void Start () {
var fileSystemWatcher = new FileSystemWatcher();
fileSystemWatcher.Path = "C:/Users/Bram Sikkens/Desktop/SealifeBestanden/ProductBestanden/";
fileSystemWatcher.Changed += FileSystemWatcher_Changed;
fileSystemWatcher.EnableRaisingEvents = true;
}
private static void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
string filename = e.Name;
Debug.Log(filename + "has changed");
GameObject coldBeveragesProductContainer = GameObject.Find("ColdBeveragesProductContainer");
}
When I execute the following code I get the error
"Find can only be executed in main thread"
How do I solve this problem?