Search Unity

Bug VSUsageUtility.isVisualScriptingUsed forces the settings file to save (taking ~4s every compile)

Discussion in 'Visual Scripting' started by SimonFireproof, May 31, 2022.

  1. SimonFireproof

    SimonFireproof

    Joined:
    May 20, 2013
    Posts:
    16
    In VSUsageUtility.cs when isVisualScriptingUsed is set for the first time, there is some code to force the VisualScriptingSettings file to save (to ensure current package version is correct):

    Code (CSharp):
    1. // Ensure our savedVersion is serialized for future migrations
    2. BoltCore.Manifest.savedVersion = BoltCore.Manifest.savedVersion;
    This runs every time there's a ReloadAssemblies (so every compile or entering play mode), and for me it takes around 4.5 seconds, which is pretty horrendous. Particularly for something that only needs to be done once per package update. As a workaround I have wrapped this code in a SessionState so it will only do it once per Unity session.

    Code (CSharp):
    1. // This code "BoltCore.Manifest.savedVersion = BoltCore.Manifest.savedVersion" is just here to force a save of the settings file
    2. // However, saving the settings file takes a few seconds and this happens everytime we switch to play mode (or Reload Assemblies).
    3. // Lets just do it once per session, unless it changes
    4. string savedVersionThisSession = SessionState.GetString("Unity.VisualScripting.BoltCore.Manifest.savedVersion", "");
    5. if (string.IsNullOrEmpty(savedVersionThisSession) || savedVersionThisSession != BoltCore.Manifest.savedVersion.ToString())
    6. {
    7.     SessionState.SetString("Unity.VisualScripting.BoltCore.Manifest.savedVersion", BoltCore.Manifest.savedVersion.ToString());
    8.    
    9.     // Ensure our savedVersion is serialized for future migrations
    10.     BoltCore.Manifest.savedVersion = BoltCore.Manifest.savedVersion;
    11. }