Visual Studio 2019 & Unity 2020 - no "Tools for Unity" Asset Database Refresh when saving

Hi,

via “Tools for Unity” I’ve enabled Asset Database Refresh in Visual Studio Pro 2019. I really like that feature as my code is automatically re-compiled in Unity when saving in Visual Studio and Unity is ready to play when switching into the Editor.

With Unity 2019 LTS this worked absolutely flawless EVERY time. However, recently I’ve updated to 2020 LTS and now this feature is working out of 50 saves maybe 3 times. So it is absolutely useless at the moment.

Has anyone the same problems?

Regards, Axel

Well, it seems I’m not the only one with this problem.

For now I’m using this fine script: Editor Compile in Background? - #26 by Elringus

It is utilizing one CPU core at 100% - but in wise foresight I’ve invested in a Ryzen 9 5950x - so it is not really a problem for me.
Hopefully this feature will work again without ugly hacks needed in the near future.

Make sure that the VS Editor package is up to date via Unity > Windows > Package Manager.

If you still notice an issue, please file a bug using Visual Studio > Help > Submit Feedback > Report a Problem.

It will help if you can explain what you see happening vs. what you expect and what steps you’re taking to reproduce the issue.

I’ve altered the file-watcher script a little bit - and it is now consuming ~1,5% of my CPU. As long as the refresh is broken I’m totally fine with this “price”.

Simply put it in any “Editor” script directory in your project, add the full path to your scripts into “ScriptPath” and you are ready to go.

Happy compiling.

using System.IO;
using System.Threading;
using UnityEditor;

[InitializeOnLoad]
public class FileWatcher
{
    public static string ScriptPath = "PATH TO YOUR SCRIPTS";
    public static bool SetRefresh;

    static FileWatcher()
    {
        ThreadPool.QueueUserWorkItem(MonitorDirectory, ScriptPath);
        EditorApplication.update += OnUpdate;
    }

    private static void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
    {
        SetRefresh = true;
    }

    private static void MonitorDirectory(object obj)
    {
        string path = (string)obj;

        FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();

        fileSystemWatcher.Path = path;

        fileSystemWatcher.IncludeSubdirectories = true;

        fileSystemWatcher.Changed += FileSystemWatcher_Changed;

        fileSystemWatcher.Created += FileSystemWatcher_Changed;

        fileSystemWatcher.Renamed += FileSystemWatcher_Changed;

        fileSystemWatcher.Deleted += FileSystemWatcher_Changed;

        fileSystemWatcher.EnableRaisingEvents = true;
    }

    private static void OnUpdate()
    {
        if (!SetRefresh) return;
        if (EditorApplication.isCompiling) return;
        if (EditorApplication.isUpdating) return;

        AssetDatabase.Refresh();
        SetRefresh = false;
    }
}

6989942–825410–FileWatcher.cs (1.33 KB)

Thanks! We’re investigating this issue: Visual Studio d2019 does not trigger Unity3d’s recompiling after saving script - Visual Studio Feedback

1 Like