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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    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
    Apologies - M1 (silicon editor version) - is unfortunately not supported yet. It's listed in limitations, sorry if that wasn't clear.

    Is Silicon most of the time you'll get message that hot-reload happened but the method call was not actually redirected. This is down to detour library not supporting silicon CPU architecture.

    1) On force-refresh and 'Looks like change to: /a/b/c.cs have already been added for processing. This can happen if you have multiple file watchers set in a way that they overlap' - do you have multiple file-watchers? I've not seen this one happening yet. The code there check if changes to say a.cs files are not very close together, within 0.5s - if they are it'll just warn you about it and continue. Shouldn't be anything wrong there.

    The reason why it doesn't work though - is silicon architecture (as described above)

    2) There's an existing limitation when editing generic methods (getters are also methods) if not supported. I'm not sure why you're getting error, on my end with your example I'm getting a warning:
    'FSR: Type for method: 'static Test.T Test.Singleton`1<Test.T>::get_Inst()' is generic. Hot-Reload for generic types is not supported yet, you won't see changes for that type.'

    Just to circle back though - the main issue is lack of M1 support - even if we can get 1/2 resolved they'll also fail on that support part, sorry.

    Happy to get the refund rolling for you if you don't have use for the asset without M1/silicon support.
     
  2. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    You're right, it looks like partial classes are not supported.

    Sorry, that wasn't in the limitations (added now).

    Let me know if that's a show stopper for you.
     
  3. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Thanks Omanuke, I've added that on top of docs section
     
  4. Adunato

    Adunato

    Joined:
    Nov 3, 2018
    Posts:
    28
    Hello @ChrisHandzlik , just purchased and imported FSR. My project is quite large (both own namespace as well as many add-ons) however, it is well divided into assemblies so that only the required assembly is recompiled on change., all this is just basic Unity best practice of course. Currently my compiling time is minimal however the "Reload Script Assemblies" followed by the editor update of its views can take easly 30s.

    I was hoping your script would (somehow) shorten the whole reloading time, but I can't see any gain whatsoever in the two bottlenecks above.

    This was done by modifying one MonoBehaviour file in editor mode (non play). I have not touched any of the settings, and left them on default. I trigger recompilation manually (CTRL+R)

    Am I doing something wrong, or is assembly reload and editor update outside the scope of this add on?
     
  5. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Hi @Adunato, asset will would only in playmode. Outside of it you'd still need to do normal Unity recompile.

    If you try to
    1) enter playmode
    2) make change
    3) you should see change and console logs, you shouldn't see normal Unity 'reloading script assemblies' tab
     
  6. Adunato

    Adunato

    Joined:
    Nov 3, 2018
    Posts:
    28
    Duh.. It's really hard to blame you for not making it clear as it's basically the name of the addon :)

    Thanks, not what I bought it for but certainly useful and it is indeed super fast, so very happy with it.

    Out of interest, is editor mode compiling optimization something you are considering looking into? I think it would find a good demand.
     
  7. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Yeah - it's nearly there and will come out as an experimental feature with next release.

    To be honest - I've found it quite lacking (especially that there are some limitations around compilation) - it was much nicer for me to just use playmode workflow.

    But I'll be making that available with that disclaimer so you should be able to try out soon
     
  8. Adunato

    Adunato

    Joined:
    Nov 3, 2018
    Posts:
    28
    Sounds great, thanks
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,789
    Hi! After importing the plugin, ITriggerable interface inside ImmersiveVRTools.Common.Runtime.dll caused a name conflict with an ITriggerable interface we had in our project. Could you please put yours in a namespace of its own? Also the "new AssemblyChangesLoaderEditorOptionsNeededInBuild()" line in FastScriptReloadManager seems to be obsolete. Though this one is not a high priority, could you fix it in a future release?
     
  10. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Hi, thanks for checking the asset out, hope it works well for you.

    Sure will do, obsolete attribute is gone for new release.

    Thanks for pointing that ITriggerable, I'll try to get that DLL swapped for files and skin down contents as not all of it is used (bit of a common lib for few projects)

    Feel free to replace common libs with files attached (you might need to adjust asmdef and add constraints so they don't end up in build.

    btw: love your tools, especially runtime inspector.
     

    Attached Files:

    yasirkula likes this.
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,789
    Thank you for the prompt response and your kind words :D I haven't gotten the chance to really test the asset yet but I'm excited about it!
     
    ChrisHandzlik likes this.
  12. c6u2

    c6u2

    Joined:
    Nov 15, 2013
    Posts:
    31
    When I do not check "auto refresh" and select "recompile after finished playing", the exsample scene does not change the game result, and the error message is shown in the screenshot
     

    Attached Files:

  13. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    @c6u2 if you have a look in that file that first error references, can you please share contents?

    Quite likely there's a compilation error, this is usually down to:
    1) General compilation error, maybe typo or something similar
    2) Incorrect rewriting by asset - although I've not seen it yet with example script.
     
  14. c6u2

    c6u2

    Joined:
    Nov 15, 2013
    Posts:
    31
    I have a comp Screenshot in append file.
     

    Attached Files:

  15. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
  16. c6u2

    c6u2

    Joined:
    Nov 15, 2013
    Posts:
    31
    Thank you, this is feasible.
    But when open my own scene,and test in my script,there have some other error,How to solve it?
     

    Attached Files:

  17. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Looks like something kills the whole thread, in that new project do you see Unity 'reloading script assemblies' when you make a change in playmode? Maybe auto refresh is still enabled there?
     
  18. c6u2

    c6u2

    Joined:
    Nov 15, 2013
    Posts:
    31
    yes,I find auto refresh is tick-on,and I set off again.But error still in.
    and...when I test the NewMonoBehaviourTest in Graph.cs.Also two error occurred.Is there any connection between them?
     

    Attached Files:

  19. bakira

    bakira

    Joined:
    Jul 1, 2016
    Posts:
    19
    I can't use this asset because I only develop with m1 Mac.
    I would be grateful if you could refund me.
     
  20. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
  21. c6u2

    c6u2

    Joined:
    Nov 15, 2013
    Posts:
    31
    I don't want to refund. I think it's reasonable that many people praise this plug-in, but it doesn't seem to help my project at present. Please help me
     
  22. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,272
    you have "Script Changes While Playing" set to "Recompile And Continue Playing" - try to change this (with Auto Refresh off the intention was this should be probably ignored but it might not be the case) --

    btw this (Auto Refresh) editor setting is something not very user friendly currently I think - should be per rather project IMHO
    ^ that's just towards UT/Editor, not asset itself
    (generic Editor remark: this makes the asset problematic to use when working on more than one project across different versions (which is for me almost constantly the case) and I want Unity default auto refresh behavior in some, but not in others)
     
    Last edited: Feb 21, 2023
  23. c6u2

    c6u2

    Joined:
    Nov 15, 2013
    Posts:
    31
    Thank you~The problem of Auto Refresh have resolved.
    Now the script in the project cannot be hot updated, and an error will be reported.
    The NewMonoBehaviorTest in Graph.cs in the example will also report an error after it is activated and refreshed.
     
  24. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Sorry mate, the refund message for for Bakiras post not yours.

    Glad auto-refresh is sorted, what error message are you getting?
     
  25. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Btw guys, just a quick message I'm running a technical blog series on how fast script reload works and also share working code (without additional features) - so core parts are standing out.

    Currently I've done:
    1) Building hot reload functionality
    2) Building hot reload for Unity builds / running directly on device

    But there's more coming, like:
    - using Roslyn to rewrite your code
    - digging deeper in IL / why it works
    - some rewrite hackery to get additional fields working without full-reload

    If you're interested here's github with code:
    https://github.com/handzlikchris/BuildingHotReloadForUnity

    @yasirkula @natteo - just linking you in as I know you're also building Unity tools, hopefully you'll find that interesting!
     
  26. bakira

    bakira

    Joined:
    Jul 1, 2016
    Posts:
    19
  27. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Cool - thanks, it usually takes Unity few days before they push the ticket my way. But once they do I'll get it approved.
     
  28. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    Hello there,
    I added this asset in my project Unity 2021.3.16
    I got this error when I reload with CMD + R

    Failed to find entry-points:
    System.Exception: Unexpected exception while collecting types in assembly `FastScriptReload.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null` ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'ImmersiveVRTools.Common.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
    at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00105] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    at zzzUnity.Burst.CodeGen.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00039] in <a2dd15248a25411e914af2a2c82fb63f>:0
    at Burst.Compiler.IL.AssemblyLoader.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00079] in <a2dd15248a25411e914af2a2c82fb63f>:0
    at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00038] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    at Mono.Cecil.TypeReference.Resolve () [0x00006] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    at Burst.Compiler.IL.Server.EntryPointMethodFinder.CollectGenericTypeInstances (Mono.Cecil.TypeReference type, System.Collections.Generic.List`1[T] types, System.Collections.Generic.HashSet`1[T] visited) [0x0002f] in <a2dd15248a25411e914af2a2c82fb63f>:0
    at Burst.Compiler.IL.Server.EntryPointMethodFinder.CollectGenericTypeInstances (Mono.Cecil.AssemblyDefinition assembly, System.Collections.Generic.List`1[T] types, System.Collections.Generic.HashSet`1[T] visited) [0x00057] in <a2dd15248a25411e914af2a2c82fb63f>:0
    at Burst.Compiler.IL.Server.EntryPointMethodFinder.FindEntryPoints (System.String[] rootAssemblyNames, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Server.ProfileDelegate profileCallback, System.Boolean includeRootAssemblyReferences, System.Boolean splitTargets, Burst.Compiler.IL.Helpers.DebugLogWriter debugWriter) [0x0019d] in <a2dd15248a25411e914af2a2c82fb63f>:0
     
  29. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    @BenoitFreslon is it always there? I remember seeing something similar (although not Burst related) on import but that was one-off and cleared on playmode
     
  30. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    Yes I got this error when I reload.

    upload_2023-3-14_9-53-36.png
     
  31. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Alright, that's first time I see this one. Probably some load issue that's specific on your end.

    What version of Unity you're using?

    I think fastest fix will be to simply replace that dll with code - it's a common code library, you can download it here:
    https://drive.google.com/file/d/14iu3BUJQkskNNUJWq060k14mv4Nvcy_m/view?usp=share_link

    Then
    1) remove ImmersiveVRTools.Common.Editor.dll from '<your proj path>\Assets\FastScriptReload\Plugins\ImmersiveVrToolsCommon'

    2) extract zipped file to that directory

    3) You probably going to get some errors as assemblies are explicily referenced,
    eg for 'FastScriptReload.Editor' asm def you'll need to remove Assembly Reference and inlcude it in Assembly Definition Reference
    upload_2023-3-14_11-12-58.png

    There's going to be 2-3 asm defs like that.

    The common library nearly never changes - and for next updates I'm intending to remove DLL altogether and include code so you should be good for updates from 1.5
     
  32. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    I'm using Unity 2021.3.16f macOS

    I deleted the ImmersiveVRTools.Common.Editor.dll
    I added the Editor folder in the ImmersiveVrToolsCommon folder


    I can't find the ImmersiveVRTools.Common.Editor.dll

    upload_2023-3-14_16-20-40.png

    I'm not familiar with Assembly references. actually.
     
  33. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    No worries, the dll is now gone replaced with asmdef, you can add it under 'Assembly Definition References', same as FastScriptReload.Runtime is there now
     
  34. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    1.4 is now out with:
    • added experimental editor-mode hot-reload, you'll need to opt in via Start Screen -> Editor Hot-Reload (please read the notes on that page, playmode workflow is still far superior)
    • you can now define User Script Rewrite Overrides - which will allow you to overcome most of existing limitations that cause compilation errors (on a one by one basis)
    • big optimization in how long hot-reload part will take, first call will be unaffected when type cache is build but subsequent calls will be significantly quicker
    • added 'Exclude References' options - this allows to remove specific dll references from dynamically compiled code (as in some cases you may get 'type defined in both assembly x.dll and y.dll'
    • destructors will no longer cause compilation error
    • (options opt-in) script rewriting can optionally emit comment - why change was made to help with troubleshooting issues
    • Unity assembly reload can be forced off via LockAssemblyReload if specified in options - sometimes even though Auto-Refresh is turned off Editor still tries to recompile changes in playmode which prevents FSR from working
    • new fields support (experimental) will be enabled by default
     
    r137 and Walter_Hulsebos like this.
  35. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Some more progress on 1.5, getting limitations trimmed down!

    - hot-reloading internal interfaces / classes would no longer cause compilation error
    - OnScriptHotReload method can be added at runtime
     
  36. Graham-B

    Graham-B

    Joined:
    Feb 27, 2013
    Posts:
    321
    Asset store version is still 1.3, where can we get 1.4?
     
  37. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    @Graham-B should be 1.4. Are you not checking Live Script Reload by a chance? The release for those is slightly different. If you already got LSR you can just get FSR for free. Not 100% confirmed that Live script reload will work with new version (that's why I'm releaseing them separately)

    upload_2023-3-16_17-14-56.png
     
  38. Graham-B

    Graham-B

    Joined:
    Feb 27, 2013
    Posts:
    321
    Thanks, that was it!
     
    ChrisHandzlik likes this.
  39. Biyao

    Biyao

    Joined:
    Oct 25, 2017
    Posts:
    1
    When my code has errors and compilation errors are reported, the following error reports will be consistently displayed upload_2023-3-24_18-29-31.png
     
  40. unity_YcyoOlOya1TvAQ

    unity_YcyoOlOya1TvAQ

    Joined:
    May 8, 2020
    Posts:
    1
    Having trouble in partial class, recompliing will ignore other partial of current file.
     
  41. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    I'll check it out, maybe some kind of loop. Does it always happen? are you on version 1.4?
     
  42. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Apoligies, partial classes are part of limitations (for now - there'll be coming a fix for it) and won't be properly reloaded
     
  43. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Just tried that, but can't recreate. Can you please provide some more details?

    Generally error message is displayed once-per recompile try.

    Just off top of my head you that change could be firing multiple times.

    If you could share a screenrecording that'd help a lot, thanks.
     
  44. tommox86

    tommox86

    Joined:
    Apr 30, 2015
    Posts:
    81
    modifying a partial class causes compilaton failure.. any eta on when will the fix be out for this?
     
  45. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    I've moved its priority up as this comes bit more often.

    It shouldn't be technically difficult. I think next week I'll likely have something. Will drop you a message when I do.
     
    tommox86 likes this.
  46. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    Hello, I got an issue when I press the play button it takes 18 seconds before the game is playing on macOS only.
    I'm also check the "Enter play mode options" to accelerate the workflow but I got the same result without this options.

    upload_2023-3-31_1-44-49.png

    Unity 2022, Unity 2021.

    Plugin 1.4

    upload_2023-3-31_1-43-51.png
     
  47. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Hi,

    Are you on MacOS (silicon) - this one is not yet supported and you won't get hot reload behaviour there - sorry. Just Rosetta (Intel) version will work for now.

    It shouldn't really add up to startup time though, unless something gets really wrong.

    Can you have a look in profiler what takes time, please? I'll then can dig into that.

    PS: really the only thing that happens on start is FileWatchers initalization, I've seen sometimes this gets weird, if you have a lot of script files in your project you could try to narrow down watched directory a bit.
     

    Attached Files:

  48. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    Hello, I'm on Mac Intel.

    Indeed the File Watchers Setup take 45 seconds instead 0.1 seconds on my project. I got this issue on Mac only not on Windows.

    I got few scripts but not too much.

     
  49. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    198
    Alright - that makes sense. I'm exactly sure how to approach File Watcher issue without ripping that whole file-changed detection off. It's a Unity/system part so there's little I can do there to optimize.

    Is an Editor update an option for you at all?

    Alternatively I could add 'reload' context-menu so you could right click on a file and force a reload.

    Unfortunately experience there is simply not as smooth as auto change detection.

    Would that work for your workflow?
     
  50. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    74
    Amazing, I cant really believe this works. Will test it on some bigger projects soon!
     
    ChrisHandzlik likes this.