Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[NOW OPEN SOURCE] Fast Script Reload (1. Play 2. Make change 3. See results)

Discussion in 'Assets and Asset Store' started by ChrisHandzlik, Nov 16, 2022.

  1. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    I've got some big news! Fast Script Reload just went open source!

    I really appreciate that you guys have supported project early on. I also do hope you won't feel out of pocket with that change. Marketing took most of my time in March. Actually taking me away from making product better.

    With this change I plan to reclaim that time and be able to deliver better tool.

    FSR had fantastic reception so far and I think getting it to as many devs as possible will benefit the whole community.

    Nothing changes on support side, issues will be a priority.

    I also have a big ask. I'd love to continue making the product better.
    With open source this means lots of users and working out financials later.

    If you could mention FSR to other game devs or simply star the repo that'd be HUGE help!

    Thanks again!

    https://github.com/handzlikchris/FastScriptReload
     
  2. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    1.5 is now out with some good stuff in there!

    - you can now import FSR as a package from github page
    - hot-reloading internal interfaces / classes would no longer cause compilation error
    - OnScriptHotReload method can be added at runtime
    - builder functions will be correctly rewritten
    - hot reload status (red / green) will be visible in project panel next to changed script
    - compilation error reporting will be much improved, project panel will allow to click error next to actual file for more details and workarounds
    - all type declarations that were appended with __Patched_ postfix to avoid name collisions will also have all corresponding identifiers changed
    - OnScriptHotReload methods will also be called in editor-workflow

    Best to get this version from github, releases to the store will lag a bit due to review
     
    akuno likes this.
  3. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    Hi, I just started to use Fast Script Reload, which could save me a lot of time, but when I update my code at runtime, I get this compilation error:

    Code (CSharp):
    1. error CS1729: 'WheelsManager' does not contain a constructor that takes 0 arguments
    The thing is there is a Constructor with 0 arguments, but it's private, because I use the Singleton Pattern (cf code bellow).

    If I turn my constructor to public, then recompile, then relaunch,-> it works, I can update at runtime. But I would like to be able to use my constructors as private, to ensure to follow the pattern correctly (and ensure there is only 1 instance). I use this a lot.
    Is there a way to use private constructor? Or could you please update it to take that case?

    Code (CSharp):
    1.  
    2.  public class WheelsManager
    3.  {
    4.         #region Singleton
    5.         private static WheelsManager _instance;
    6.         public static WheelsManager Instance
    7.         {
    8.             get
    9.             {
    10.                 if (_instance == null)
    11.                 {
    12.                     _instance = new WheelsManager();
    13.                 }
    14.                 return _instance;
    15.             }
    16.         }
    17.         #endregion
    18.  
    19.        private WheelsManager()
    20.         {
    21.         }
    22.  
    23. ...
    24. }
    25.  
    Thanks
     
    Last edited: Apr 21, 2023
  4. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    I'd be good to see your generated SourceCodeCombined file (when error happens you'll get it's location)

    Probably something doens't go quite right on rewrite part
     
  5. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    I have isolated the code to double check that it cannot be something else, and to make it clearer. I still get the error.

    Now the class only contains this:

    Code (CSharp):
    1.  
    2. public class SingletonTest
    3. {
    4.     private static SingletonTest _instance;
    5.  
    6.     public static SingletonTest Instance
    7.     {
    8.         get
    9.         {
    10.             if (_instance == null)
    11.             {
    12.                 _instance = new SingletonTest();
    13.             }
    14.             return _instance;
    15.         }
    16.     }
    17.        
    18.     private SingletonTest()
    19.     {
    20.              
    21.     }
    22. }
    23.  
    The generated SourceCodeCombined file:

    Code (CSharp):
    1.  
    2.  
    3. public class SingletonTest__Patched_{
    4.     private static SingletonTest _instance;
    5.  
    6.     public static SingletonTest Instance
    7.     {
    8.         get
    9.         {
    10.             if (_instance == null)
    11.             {
    12.                 _instance = new SingletonTest();
    13.             }
    14.             return _instance;
    15.         }
    16.     }
    17.        
    18.     private SingletonTest__Patched_()
    19.     {
    20.              
    21.     }
    22.  
    23. private static System.Collections.Generic.Dictionary<string, System.Func<object>> __Patched_NewFieldNameToInitialValueFn = new System.Collections.Generic.Dictionary<string, System.Func<object>>{};
    24.  
    25.  
    26. private static System.Collections.Generic.Dictionary<string, System.Func<object>> __Patched_NewFieldsToGetTypeFnDictionaryFieldName = new System.Collections.Generic.Dictionary<string, System.Func<object>>{};
    27.  
    28. }
    29.  
    30.  

    The Error:
    Code (CSharp):
    1. FSR: Error when updating files: 'SingletonTest.cs', System.Exception: Compiler failed to produce the assembly. Output: '/var/folders/lc/hr4_qn5s1dz3ygxt1ps8qvcw0000gn/T/58b470c1d25c469b9035bac8cfd8aec0.SourceCodeCombined.cs(26,33): [B]error CS1729: 'SingletonTest' does not contain a constructor that takes 0 arguments'[/B]
    2.   at FastScriptReload.Editor.Compilation.DotnetExeDynamicCompilation.ExecuteDotnetExeCompilation (System.String dotnetExePath, System.String cscDll, System.String rspFile, System.String outLibraryPath, System.Collections.Generic.List`1[System.String]& outputMessages) [0x001fe] in /Users/remi/Documents/UnityProjects/CreateIn3D/Assets/FastScriptReload/Scripts/Editor/Compilation/DotnetExeCompilator.cs:256
    3.   at FastScriptReload.Editor.Compilation.DotnetExeDynamicCompilation.Compile (System.Collections.Generic.List`1[T] filePathsWithSourceCode, ImmersiveVRTools.Runtime.Common.UnityMainThreadDispatcher unityMainThreadDispatcher) [0x00178] in /Users/remi/Documents/UnityProjects/CreateIn3D/Assets/FastScriptReload/Scripts/Editor/Compilation/DotnetExeCompilator.cs:139
    4.   at FastScriptReload.Editor.Compilation.DynamicAssemblyCompiler.Compile (System.Collections.Generic.List`1[T] filePathsWithSourceCode, ImmersiveVRTools.Runtime.Common.UnityMainThreadDispatcher unityMainThreadDispatcher) [0x0000e] in /Users/remi/Documents/UnityProjects/CreateIn3D/Assets/FastScriptReload/Scripts/Editor/Compilation/DynamicAssemblyCompiler.cs:23
    5.   at FastScriptReload.Editor.FastScriptReloadManager+<>c__DisplayClass45_1.<TriggerReloadForChangedFiles>b__2 () [0x00063] in /Users/remi/Documents/UnityProjects/CreateIn3D/Assets/FastScriptReload/Scripts/Editor/FastScriptReloadManager.cs:367
    6. UnityEngine.Logger:Log (UnityEngine.LogType,object)
    7. ImmersiveVrToolsCommon.Runtime.Logging.LoggerScoped:LogInternal (UnityEngine.LogType,object)
    8. ImmersiveVrToolsCommon.Runtime.Logging.LoggerScoped:LogError (object)
    9. FastScriptReload.Editor.FastScriptReloadManager/<>c__DisplayClass45_1:<TriggerReloadForChangedFiles>b__2 () (at Assets/FastScriptReload/Scripts/Editor/FastScriptReloadManager.cs:410)
    10. System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
     
  6. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
  7. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
  8. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    Hi @ChrisHandzlik, it looks like if I recompile when it's not running (by using the shortcut of Fast Script Reload) and very quickly I use the shortcut to Play/Start by game, but the compilation has not finished, then it crashes Unity. (For info I use a Mac). I understand that it cannot run if the compilation is not finished, but sometimes I go too fast, and this happens. It would be good if it could just prevent to play instead of crashing Unity.
     
  9. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    @RemiSoleil thanks, that's good find. I've logged that and will have a look.

    Checking if hot-reload is in progress and preventing play mode should be straight forward. I'll look at the wider issue but in the meantime you should be able to add code in here
    FastScriptReload.Editor.FastScriptReloadManager.OnEditorApplicationOnplayModeStateChanged

    on before playmode enter, and you can check
    FastScriptReload.Editor.FastScriptReloadManager._dynamicFileHotReloadStateEntries list for FastScriptReload.Editor.DynamicFileHotReloadState.IsAwaitingCompilation

    that'd mean hot reload will be performed soon. You could then prevent entering playmode
     
  10. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    @ChrisHandzlik Thanks for taking care of the suggestions and thanks for your tool.
     
    ChrisHandzlik likes this.
  11. Sarai

    Sarai

    Joined:
    Jul 20, 2014
    Posts:
    27
    Hi, I have a question:
    after installing this package, my changes to the script is not being reflected on edit mode.

    For example, when I add a new SerializeField to the Graph class,
    upload_2023-7-26_11-3-35.png

    It didn't show (as if the code has never changed)
    upload_2023-7-26_11-3-51.png

    The changes in the runtime work tho... Any idea why?

    Anyway, thank you for this amazing package!!
     

    Attached Files:

  12. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Hi - there are some limitations to what you can hot-reload, you can check those in the docs.

    New fields are not enabled by default on older version, you can go to FastScriptReload -> Start Window and find them in settings to enable
     
  13. Sarai

    Sarai

    Joined:
    Jul 20, 2014
    Posts:
    27
    Oh that's right... that leads me to the right track.
    upload_2023-7-26_18-26-15.png

    Change the Asset Pipeline -> Auto Refresh to Enabled Outside Playmode did what I wanted.
    upload_2023-7-26_18-27-48.png
    Thanks for the reply
     
    ChrisHandzlik likes this.
  14. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    Hi @ChrisHandzlik , I have upgraded to Unity 2022.3.7f1 (LTS), and now it seams your plugin does not work anymore. In runtime, when I update/save my source code, there is no log in the console anymore, and it does not take care of the update anymore.
     
  15. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Hi @RemiSoleli, I'm running tests on 2022.3.4f1 and that were all fine.

    Was the asset working for you in previous versions of Unity?
     
  16. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    Hi @ChrisHandzlik, yes, it used to work before.
    I reinstalled it, and it didn't fix the problem.
    And today I tried on an empty/new project, and it also doesn't work.
    For info I use a Mac.

    I don't know if there is a way to activate more of your log? Or if I should add some logs somewhere to find out where the problem may come from.
     
  17. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    I suspect the issue is with file watchers not firing (this happens for some users, not sure what changed that it may have stopped firing for you but I've seen this happen)

    There's a new addition for that (but you'll have to download latest-commit from github as it's not yet in the release)

    Effectively it'll start watching files manually bypassing FileWatcher API.
    https://github.com/handzlikchris/FastScriptReload
     
  18. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    Hi @ChrisHandzlik ,
    I have download the github code. Activated the parameter like on your picture. It still does not work.
    And when I rebuild with the shortcut Command+Fn+R, then it start compiling and stay on 0% probably forever. Or at least in 16 minutes it's still at 0%.
    I tried to restart. Same issue. I removed FastScriptReload-master folder and readd it again. Same issue. When I remove it and rebuild I don't have the compiling for ever issue, so it must be related.
     
  19. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
  20. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    sorry - I've missed originally that you use Mac, are you using Intel editor verion or Silicon? For silicon one FSR does not work at all.

    Something definately odd with compiling forever - but if you're on silicon it's moot point to look into anyway.
     
  21. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    I have an Intel processor.
     
  22. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Alright - so we've got:
    1) FSR that was working previously on same setup / in same project (also in empty project)
    2) stopped working without any update to FSR itself
    3) Doesn't work on newest version (even with manual file watching)

    I think realistically you need to look at it with debugger.

    I'd start with determining if file changes are even picked up. Can you:
    1) enable custom file watchers (and restart unity just in case)
    2) Add ImmersiveVrTools_DebugEnabled compiler symbol
    3) Make sure your file-watcher setup is configured correctly, eg poiting to test-script.cs folder
    4) Make change to that test-script.cs folder

    Do you get 'File changed test-script.cs' log lines? Or any log lines?

    PS: I know you've mentioned compilation just hangs - I can't think of anything in FSR that'd cause that (and I've not seen it yet) - did you managed to get past that at all? Feels like a Unity related issue - usually if something is not right with the plugin/dlls you'll get an error.

    If you did not get past that you can try commenting out (FastScriptReload.Editor.FastScriptReloadManager.FastScriptReloadManager ctor) - this will prevent initialization and running with Editor.update. This way we can determine if it's that FSR update loop that's somehow running too long and locking it down
     
  23. RemiSoleil

    RemiSoleil

    Joined:
    May 5, 2018
    Posts:
    12
    Hi, thanks for searching a solution. I have tested more, but still can't make it for my project.

    An additional point I can see is Unity auto compile does not work anymore for me. also not on an empty project.
    I have tried to activate it with some script. (EditorPrefs.SetInt("kAutoRefresh", 1); ) but it did not fix it.
    In case you have some suggestion for that, please let me know.

    On an empty project, when I use the latest version of FSR, then at runtime if I made a modification, it works.
    But for my project, with FSR last version it still hangs. When I commented FastScriptReloadManager constructor then it did not hang. (but of course then changes at runtime was not used).