Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    203
    Are you tired of waiting for full domain-reload and script compilation every time you make a small code change?

    Me too.



    Fast Script Reload
    Iterate on code insanely fast without breaking play session. Supports any editor. 1. Play 2. Make change 3. See results

    Tool will automatically compile only what you've changed and immediately hot reload that into current play session.

    Iterate on whatever you're working on without reentering play mode over and over again.

    And you don't have to adjust your code either, just import.

    Works with any code editor.

    Quickstart
    1. Download latest release from Github, you can also get it on Asset Store (althoguh it may not be fully up to date)
    2. Play
    3. Make Code Change
    4. See results
    It's that simple.

    Unity Asset Store Best Seller
    I was really chuffed to see FSR selling over 1000 copies on Asset Store in February - propelling it to #1 best-selling for a few days and keeping on first page for most of the month.

    Gaining reviews like:
    Goosebumps and tears of joy
    Felt like I was underwater and that I can breathe again. Just buy this stuff for any serious project. Working around the limitations is just worth it.

    Now Open Source
    I've decided to fully fully open source FSR and - it's available on Github

    Thanks to anyone who got it on the store in the past, and if you're new and like it please be sure to tell about it to other devs! Simply leaving a star on github repo is huge help as well!

    Hot-Reload in development build (on device)
    You can use same hot reload functionality in actual builds / on device. Iterate quickly on deployed Android APK / standalone windows build (exe).

    One-off custom code executions on Hot-Reload
    When you need to set the stage to test your feature out.

    Add following methods to changed script:

    void OnScriptHotReload()
    {
    //do whatever you want to do with access to instance via 'this'
    }

    static void OnScriptHotReloadNoInstance()
    {
    //do whatever you want to do without instance
    //useful if you've added brand new type
    //or want to simply execute some code without |any instance created.
    //Like reload scene, call test function etc
    }

    Performance
    It's a development tool, you're not supposed to ship with it! :) Your app performance won't be affected in any meaningful way though. Biggest bit is additional memory used for your re-compiled code. Won't be visible unless you make 100s of changes in same play-session.

    Supports (Tested)
    • Windows / Mac (Intel editor version only) / Linux
    • Unity 2019.3
    • Unity 2020.3
    • Unity 2021.3
    • Unity 2022.2
    Documentation
    Full documentation is available here

    Few things to have in mind, limitations:
    • most limitations can be overcome with User Defined Script Overrides (see docs for more info)
    Generic methods and classes won't be Hot-Reloaded
    Unfortunately generics will not be Hot-Reloaded, to workaround you'd need to move code to non-generic class / method.

    Creating new public methods
    Hot-reload for new methods will only work with private methods (only called by changed code)

    Adding new fields (Experimental support added in 1.3)
    You can now add new fields and tweak them in editor! Minor limitations:

    • outside classes can not call new fields added at runtime
    • new fields will only show in editor if they were already used (at least once)
    Extensive use of nested classed / structs
    If your code-base contains lots of nested classes - you may see more compilation errors.

    Mac Silicon Editor version not supported
    On Mac only Intel Editor version is supported. For Silicon version logs will show that everything is fine but actual change will not happen at runtime

    Other minor limitations
    There are some other minor limitations, please consult full list

    Roadmap
    Soon whole roadmap will be published as Github project for better visibility.

    • more structured unit-tests, especially around script rewrite
    • add Mac/Linux support - (DONE, added with 1.1)
    • add debugger support for hot-reloaded scripts (DONE, added with 1.2)
    • allow to add new fields (adjustable in Editor) (DONE, added with 1.3)
    • editor mode support (DONE, added with 1.4)
    • better compiler support to workaround limitations
    FAQ
    • My changes no longer automatically compile / reload
    You probably allowed tool to change auto-reload to 'disabled' and have forgotten about it.

    You can reload changes manually with CTRL+R

    or reenable auto-reload - please go to Edit -> Preferences -> Asset Pipeline -> Auto Refreshand set to Enabled Outside of Playmode. This way FSR will work in playmode and Unity will do full recompile when you hit 'stop'.

    • When importing I'm getting error: 'Unable to update following assemblies: (...)/ImmersiveVRTools.Common.Runtime.dll'
    This happens occasionally, especially on upgrade between versions. It's harmless error that'll go away on play mode.

    • When upgrading between versions, eg 1.1 to 1.2 example scene cubes are pink
    This is down to reimporting 'Point' prefab. Right now plugin will make sure it's using correct shader eg. URP / Built-in but only on initial import.

    To fix please go to FastScripReload\Examples\Point\Point.prefab and search for 'Point' shader.
     
    Last edited: Apr 6, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    I assume this uses reflection to change an existing method body?
    I would welcome anything that improves iteration time. Knowing that anything below 5s is pretty damn fast for any code change still makes me want to get that down to realtime, having done a lot of scripting workflows with hot reload in the past.

    One solution to that could of course be to compile certain code modules to a DLL, as I've done in the past for implementing the hundreds of formulas the app was using while also having unit tests outside of Unity so I could just hit a button and run the tests in under 1s, rather than having to wait for recompile in the editor, domain reload, and then the TestRunner updating its GUI and initializing a test run which back then took at least 2s on top of the actual tests running. It also allowed me to read the unit test "expected values" directly from an open Excel sheet to confirm that the Excel formulas I converted to code lead to the exact same results with the same set of input values.

    Another alternative would be to program systems in a way that they can be entirely data-driven. I made myself a workflow where I press Ctrl+S in Excel, tab into the Unity editor, and the edited values appear in ScriptableObjects instantaneously (read from CSV with code generation only running whenever columns are added/removed/renamed).
     
  3. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Kind of, as far as I'm aware you can only edit existing assembly with stuff like Mono.Cecil before they are loaded (eg. after compilation).

    For runtime it's compiling just the file that you've changed and making sure existing code calls that instead.
     
  4. BetaMark

    BetaMark

    Joined:
    Sep 27, 2014
    Posts:
    229
    I do a lot of multiplayer work. Would there be a new life cycle event I could hook into to reset the network state on the domain reload? And yes, I'd you could remove the always annoying "Unity Busy", that would ease one of my key developer annoyances in Unity. I'd happily pay money.
     
  5. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Possibly, I was thinking about similar thing as in you may want to do a execute 'one-off' on hot-reload.

    It's straight forward from technical point of view but it'd then introduce code in your source file that's really just executed in editor when you reload and has nothing to do with actual non-editor workflow.

    Not ideal but I think Unity already exposes some methods like that, eg Reset() - so wouldn't be much out of existing concepts.
     
  6. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    And that is possible without editing the editor itself but with a plugin? Very interesting!

    Well, there surely are limitations, aren't there?
    What happens if I include new classes in the edited code? Or even create new classes/structs? Can I perform a change that requires two files to compile again (meaning that inbetween they will be non-compilable)?
    Are there performance disadvantages to the compiled code from this?

    Even if the answer to most of those questions is no, it would still be quite useful. Certainly have often had to make more variables serializable just to test out variations and once even added a switch statement just to test a variety of formulas.


    EDIT: Oh what happens with the data held by the instances whose script is modified?
    Like a Monobehavior where I'd add or remove fields. Do all other fields of all instances currently in the game retain their values?
    What if I modify a struct which is held by member variables in other classes?

    EDIT 2:
    Ah, is it exclusively for the content of static methods?
     
    Last edited: Nov 16, 2022
    ChrisHandzlik likes this.
  7. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Thanks @DragonCoder, great questions and some that are part of the kinks I'm looking to work out.

    There are limitations, some of which will be easier to address than others but right now I don't see big show-stopped for use case (which is rather small script iteration to see results immediately, not replacing wider compile workflow)

    Essentially your changed file goes into in-memory assembly and existing classes start calling that instead [for now methods only] - that's the core, really and due to that there are bit's that need to be worked out:

    1) No changes to editor

    2) it's not only for static methods, instance methods are fine - but data wise they are some challenges to be addressed

    3) currently you'll have data that's been copied over from original instance to new one
    - for the purpose of iteration it'll be fine, as in it'll work with same data
    - but it'll not be same data that's shown in editor
    - unless it's synchronised - which will be possible but will involve some performance overhead (still for quick dev-iteration that shouldn't matter)

    3a) adding serialized fields will be supported (but they won't show in the same play-session, as editor would need domain reload). In current play session they can be used but you want to populate them via class initializer - but that means you can iterate and then editor will pick it up as usual, if you need to change in same session it'll be changing that initialization value again)

    3b) removing existing fields - no issue, they'll be gone from editor on next load

    4) existing statics, like singletons - should be mostly straight forward, it's a reference and can be populated with existing instance

    5) Right now each file is worked on separately - and you can have multiple file (but currently will probably have issues if both changed files interact with each-other via field-references, methods/getters should be fine)

    6) Performance wise - there shouldn't be much hit, although can't tell for sure without some proper profiling session

    7) Adding new classes (non mono-behaviours) would be fine [likely little use though, you can easily refactor outside of play mode]. For new mono-behaviour classes - it'll be possible to add them in but it'd also require to swap that instance on game-object, which I want to avoid as that will trigger lifetime methods, like Start(), OnEnable() - which breaks the whole idea - so likely will be out-of-scope

    Certainly have often had to make more variables serializable just to test out variations and once even added a switch statement just to test a variety of formulas.
    That's exactly what I'm after, quick changes at runtime with immediate result. For wider changes - standard workflow is the way to keep it simple.

    There's a huge upside (at least for me as well) - just done some more testing and got that running in an Android standalone build (eg. client code change triggered from editor but then to running compiled APK) - with success. I'm looking to get that mainly to standalone-VR (which is also Android) when getting it compiled, then restart play-session into proper place is taking minutes easily - obviously you don't have to do it for every change but lots of stuff is best to be tested on device). I'll shoot some vid in few hours to follow up on that
     
    r137 and DragonCoder like this.
  8. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Alright some good progress

    1) Updated code now correctly reacts to editor changes [testUMove]
    2) Data is correctly persisted, eg previous editor data stays after your code change (and editor also correctly shows that) [testIterationCounter]
    3) Code changes made in updated code are correctly reflected in editor (testIterationCounter being incremented in Update() method)

     
    Last edited: Nov 17, 2022
    ontrigger, Ghat-Smith and DragonCoder like this.
  9. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    Certainly neat!
    Am looking forward to trying it out.
     
    ChrisHandzlik likes this.
  10. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    This looks pretty neat! Can you see any good reason why this hasn't been implemented natively? Can you make changes while the debugger is attached without, uh, crashing everything?

    I'd happily test the current version of the project if that'd be useful to you.
     
  11. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    @Baste some of that has been done some time ago via kind-of custom editor but I'm not sure what approach the dev took and it's been discontinued in 2014-15
    https://forum.unity.com/threads/livity-the-live-coding-tool-for-unity.195537/

    As to why it's not done natively - the challenge to reload whole thing is much larger (and beyond what I understand). This approach focuses just on making it seem like it's been reloaded but it is not truly.

    Although from the developer workflow perspective it feels/works that way.
    I want it to tick all major boxes for dev productivity but it'll never be a full/proper reload in technical manner.

    To answer your question - I don't think Unity is interested in half-measures as they are looking for a platform-wide solution that ticks all the boxes.

    Debugger wise - right now you won't crash with debugger but your breakpoints in changed code files won't be hit. Technically it's a new assembly. You could probably go with something like Debugger.Launch/Break and it'd likely allow you to decompile source and debug that but without debugging symbols the experience will be less than what we're used to with normal code. Still code changes this quick I'd lean in to drawing on screen / console.log rather than debugger. Technically I think it'd be possible to get some better debugger support - but not a priority in near-term.

    Thanks for the offer, I'd be sure to reach out in a week or so, need some more time to make it a bit more usable and clean up a little.
     
  12. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Bit more update, Instant reload on deployed and running Android APK
     
    Vectrex and joshcamas like this.
  13. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    APK deployed to Quest 2 VR headset (also android), got to say this for me is biggest upside.

    I'm a VR dev and lots of stuff is best tested in headset. There are workflows that allow you to connect headset with Unity (somewhat) but they'll run in a 'viewer' mode and not as a native APK - so lots of issues are hidden till you actually do full build and deployment. Looks quite promising that this pain point will go away

     
  14. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    101
    Amazing stuff. I need this! Any chance I can have a go?
     
  15. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Cool - glad you like it, I'm polishing it up right now but also submitted to asset store. It should be available in around a month at which point I'll be sending some test-codes out. I'll drop a message in this thread once ready.

    Thanks for the offer to have a look, for now I've got some small testing group set up already.
     
    Ghat-Smith and haywirephoenix like this.
  16. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Getting more stable now!

    This time round looking at Unity FPS sample which is much closer to real-word project. Following best practices with AsmDefs, separation of concerns and such.

    Code hot-reload to iterate on follow + attack mechanisms without leaving playmode.

     
  17. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    I've been quite quiet, but that's good. Busy with polishing the tool.

    There's some wider testing going and it's going quite well, we've uncovered few issues and fixed most of them. Tool works quite nicely in some bigger / real-world scenarios. And when it doesn't it'll give you options to exclude / work around the issues so you're aware.

    From technical point of view there's nothing new to share, it's just easy to use and do what's on the tin.

    I wonder if you guys could give me a bit of feedback around promo video though. I know it's not as interesting as tech but would love to get it to as many people as possible, and that means some materials that draws eyeballs and communicate the utility in straight forward way.



    Mostly interested in knowing:
    1) do you know what the tool does?
    2) did you got bored in the middle and closed?
    3) not too quick?

    Thanks
     
  18. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    this is random video feedback (personal opinions), i'd buy this kind of plugins without watching any videos..
    - seeing that unity progress bar gives stress, was about to rewind forward..(i thought it could take longer)
    - too many transitions (i know it could look "boring" without them, but too much stuff moving)
    - at first view, didn't have time to read all the texts on that first slide (after that progress bar scene)
    - code scenes: couldn't read/focus anything as the screens kept flipping, didn't catch what was happening
    - could have bit more info in the end, what platforms at least (now its same slide as previously?)
    - personally would like to know right away, if it works with visual studio
    - i guess limitations can be mentioned outside video or separate in depth video
     
    ChrisHandzlik likes this.
  19. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Thanks, those are great points.

    I'll get it somewhat toned down bit more and slowed a bit so important parts are easier to catch.

    Also will add editor support, that's definitely quite important. As you've mentioned that last slide will likely be extended bit more with content.

    Limitations and more in depth stuff will follow either in text or on following feature screenshots.
     
  20. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    150
    I like it, but the "frame-swap" when demonstrating hot-reload is distracting.
     
  21. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Thanks - maybe just half screen code and half preview would work better. I'll give this a go
     
  22. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Going to agree with everyone here - it's super-important that when you show of your core feature, you don't cover it up with a screen transition!

    You also probably always want to show the Unity play bar, so it's visible that the editor is, indeed, in play mode.

    I'd also include "works with any code editor" so people don't think it requires VS or some other nonsense
     
  23. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Thanks again for all suggestions regarding marketing stuff, wasn't expecting this many responses, really appreciate that!

    It's now incorporated into video, slowed down a bit, toned down transitions and added more info slide at last one.

    Would you know what the tool does after watching?
     
  24. pbear-baowei

    pbear-baowei

    Joined:
    Nov 24, 2021
    Posts:
    1
    looks great. how can I use it?
     
  25. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Thanks - it's in the queue for asset store, looks like should be published in 1-2 weeks
     
  26. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Guys, this is now wrapped up and released.

    Get Fast Script Reload on asset store

    Big thanks for all help and support @CodeSmile @BetaMark @DragonCoder @Baste @haywirephoenix @TheVirtualMunk @mgear @pbear-baowei

    If you'd like to support it even further grab a copy.

    I'm also very happy to provide you with a free code as an appreciation token - just drop me a DM.

    Also - it'd be fantastic if you could share your feedback as a review so we can spread the word!

    Hope it holds up to expectations, development will continue as there'll be cases where compilation falls apart - fingers crossed just a few though!

    Thanks again

    PS: a version that'll allow you to reload on devices (Android / Standalone) is just reviewed now and will land in a few days, it's really same tool and there'll be like a $5 upgrade path to take - no need to wait - you won't be left out
     
    Last edited: Dec 15, 2022
    mgear and TheVirtualMunk like this.
  27. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    150
    Congrats on the release!

    I'm really interested in trying this out! We're both on the Meta Quest (Pro) and MagicLeap 2 (Android x86_64) platforms, so this could potentially be a huge timesaver!
     
  28. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Cool - just DMd you in case you want to check editor version as well.

    I think asset store is bogged down as the other one is stuck in pending (few business days). It's quite close to xmas now I may need to push the release for other other one to new year so I can properly support it.
     
  29. psk131

    psk131

    Joined:
    Aug 19, 2016
    Posts:
    5
    This could be a really useful asset! Unfortunately, looks like it conflicts with Unity's Collections package which is required by many other assets: https://docs.unity3d.com/Packages/com.unity.collections@1.4/manual/index.html

    From console:
    Library\PackageCache\com.unity.collections@1.4.0\Unity.Collections\xxHash3.cs(465,27): error CS0234: The type or namespace name 'umul128' does not exist in the namespace 'Common' (are you missing an assembly reference?)

    Same problem in
    Unity 2020.3.43f1, Collections 1.4.0
    Unity 2021.3.16f1, Collections 1.2.4
    Unity 2022.2.1f1, Collections 1.2.4 / Collections 2.1.0-pre.6

    Collections package works fine until this asset is installed.
     
  30. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
  31. psk131

    psk131

    Joined:
    Aug 19, 2016
    Posts:
    5
    Thanks, but I still get the same error after updating "ImmersiveVRTools.Common.Runtime.dll". Should "ImmersiveVRTools.Common.Editor.dll" be also updated?
     
  32. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Last edited: Dec 18, 2022
  33. Blade_Master_2020

    Blade_Master_2020

    Joined:
    Aug 3, 2019
    Posts:
    38
    Thansk, it's working now.
     
    ChrisHandzlik likes this.
  34. psk131

    psk131

    Joined:
    Aug 19, 2016
    Posts:
    5
    Yes, it works now! This will make development so much faster :cool:

    Looks like you are using Harmony library like many Unity game mods – that's clever!
     
    ChrisHandzlik likes this.
  35. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Cool, that's great to hear.

    Yeah Harmony is a fantasic lib (and also MonoMod that I think it is extending). It has a ton of uses.
     
  36. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Some users are reporting they are getting 'System.IO.FileNotFoundException' on code change.

    There seems to be an issue happening with FileWatcher and resolving proper path.
    https://issuetracker.unity3d.com/issues/filesystemwatcher-returns-bad-file-path

    As a workaround, please:
    1. go to '<your unity project path>\Assets\FastScriptReload\Scripts\Editor\FastScriptReloadManager.cs'

    And whole OnWatchedFileChange method to:
    Code (CSharp):
    1.         private void OnWatchedFileChange(object source, FileSystemEventArgs e)
    2.         {
    3.             if (_lastPlayModeStateChange != PlayModeStateChange.EnteredPlayMode)
    4.             {
    5. #if FastScriptReload_DebugEnabled
    6.             Debug.Log($"Application not playing, change to: {e.Name} won't be compiled and hot reloaded");
    7. #endif
    8.                 return;
    9.             }
    10.  
    11.             if (_currentFileExclusions != null && _currentFileExclusions.Any(fp => e.FullPath.Replace("\\", "/").EndsWith(fp)))
    12.             {
    13.                 Debug.Log($"File: '{e.FullPath}' changed, but marked as exclusion. Hot-Reload will not be performed. You can manage exclusions via" +
    14.                           $"\r\nRight click context menu (Fast Script Reload > Add / Remove Hot-Reload exclusion)" +
    15.                           $"\r\nor via Window -> Fast Script Reload -> Start Screen -> Exclusion menu");
    16.          
    17.                 return;
    18.             }
    19.  
    20.             var changedFileName = new FileInfo(e.FullPath).Name;
    21.             var fileFoundInAssets = Directory.GetFiles(DataPath, changedFileName, SearchOption.AllDirectories);
    22.             if (fileFoundInAssets.Length == 0)
    23.             {
    24.                 Debug.LogWarning($"Unable to find file '{changedFileName}' via FileWatcherBugWorkaround, changes will not be reloaded, please contact support.");
    25.             }
    26.             else
    27.             {
    28.                 _dynamicFileHotReloadStateEntries.Add(new DynamicFileHotReloadState(fileFoundInAssets[0], DateTime.UtcNow));
    29.             }
    30.         }
     
  37. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Btw there's now a discord server set up for support / chats

    You can join via this link
     
    Vectrex and LinnPeder like this.
  38. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Some users are getting full reload on any change

    Unity editor has settings that trigger fill reload on code / assets change. You can adjust that via:

    a) Edit -> Preferences
    b) Asset Pipeline
    c) Auto Refresh - set to 'Enabled outside of Playmode' - with that editor will only recompile your changes when you exist playmode which will allow tool to do it's job quickly.

    You can also set to 'Disabled' (then you can refresh with CTRL+R)
     
    Vectrex likes this.
  39. anehta

    anehta

    Joined:
    Feb 23, 2021
    Posts:
    5
    I have to pray for you, you gotta go to heaven, you saved my life
     
    Vectrex and ChrisHandzlik like this.
  40. anehta

    anehta

    Joined:
    Feb 23, 2021
    Posts:
    5
    we dont need to set 'AutoRefresh' to false;
    we can add this code in your project
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3.  
    4. namespace UnityEditor.Utility
    5. {
    6.     /// <summary>
    7.     /// Disables the editor Auto Refresh asset import behavior when in playing mode and restores it on return to edit mode.
    8.     /// </summary>
    9.     [InitializeOnLoad]
    10.     public static class DisableAssetAutoImportOnPlay
    11.     {
    12.         /// <summary>
    13.         /// Due to InitializeOnLoadAttribute, this static Constructor will be called when this editor assembly loads (on startup and on AppDomain restart after compile).
    14.         /// </summary>
    15.         static DisableAssetAutoImportOnPlay()
    16.         {
    17.             EditorApplication.playModeStateChanged += DisableAssetAutoImportOnPlay.OnEditorApplicationPlayModeStateChanged;
    18.         }
    19.         /// <summary>
    20.         /// Called when the EditorApplication.playModeStateChanged event fires
    21.         /// </summary>
    22.         /// <param name="playingState"></param>
    23.         private static void OnEditorApplicationPlayModeStateChanged(PlayModeStateChange playingState)
    24.         {
    25.             switch (playingState)
    26.             {
    27.                 // Called the moment after the user presses the Play button.
    28.                 case PlayModeStateChange.ExitingEditMode:
    29.                     break;
    30.                 // Called when the initial scene is loaded and first rendered, after ExitingEditMode..
    31.                 case PlayModeStateChange.EnteredPlayMode:
    32.                     if (EditorPrefs.HasKey("kAutoRefresh"))
    33.                         EditorPrefs.SetBool("kAutoRefresh", false);
    34.                     break;
    35.                 // Called the moment after the user presses the Stop button.
    36.                 //case PlayModeStateChange.ExitingPlayMode:
    37.                 //    break;
    38.                 // Called after the current scene is unloaded, after ExitingPlayMode.
    39.                 case PlayModeStateChange.EnteredEditMode:
    40.                     if (EditorPrefs.HasKey("kAutoRefresh"))
    41.                         EditorPrefs.SetBool("kAutoRefresh", true);
    42.                     break;
    43.                 default:
    44.                     break;
    45.             }
    46.         }
    47.     }
    48. }
    49.  
    50. #endif
     
  41. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    That's awesome, thanks!
     
  42. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Even better as it'd seem asset made you post for the first time on the forum ;)
     
  43. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    works great! but pressing play button is really slow takes like 5 seconds on big project
     
  44. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Alright, I think you may be getting into FileWatcher performance issue that @anehta narrowed down and posted some details in discord.

    upload_2022-12-29_8-12-47.png

    There's an option added in 1.1 that allows you to adjust which directories are watched.
    (I've sent you a link to v1.1 on PM as it's currently reviewed for store release.)

    It'll allow you to go to Window -> Fast Script Reload -> File Watchers - there's some notes how to adjust (if needed) - just point it to directory/ries that you want to change files in.

    Also there's a bunch of bug fixes and some startup perf fixed that could get it improved.

    That's how other dev set it yesterday and seems to have made a difference, hope same is for you.
    upload_2022-12-29_8-16-39.png

    Let me know if it helps / doesn't help. If there's no improvement good next step would be if you could capture and send profiler info from startup. Or some more details that would help me recreate.
     
    friuns3 likes this.
  45. Vectrex

    Vectrex

    Joined:
    Oct 31, 2009
    Posts:
    267
    I have to say, this is easily the greatest thing to happen with Unity in a decade (since Livity died!). I've only tried it a little bit, but it's got me excited that it works at all. Of all the things Unity work on, it's done my head in that something like Livity was possible, yet hasn't been recreated since.
    The fact that you can make this work at all and also that Unity have been actually trying to speed up interation time, tells me they really aren't getting it.
    Perhaps they didn't want to do this because it's not going to work for everything? Do they think it would confuse beginners when they get some inconsistant behaviours? This seems to be their main sticking point with a lot of features. I think this is flawed thinking for a tool that can help 80% of the time.
    Interation time and restarting the project contantly have always been a major creative and 'in the zone' killer for me. Even Unreal can't change code while it's running. They should add this to Unity immediately.
    I'm a teacher and will be using this in the team projects we work on, so I'll take notes and give bug feedback and feature ideas. eg You inspired me to make a little editor window that can recall Awake and Start or destroy and reinstatiate the GO. It doesn't work 100% of the time (the prefab checker doesn't work in playmode I think?), but who cares! Feel free to steal it if you think it'd suit this plugin.
    upload_2022-12-30_15-54-21.png

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Reflection;
    5. using UnityEditor;
    6. using UnityEngine;
    7.  
    8. public class RestartGameObject : EditorWindow
    9. {
    10.     // Add menu named "My Window" to the Window menu
    11.     [MenuItem("Window/Restart GameObject")]
    12.     static void Init()
    13.     {
    14.         // Get existing open window or if none, make a new one:
    15.         RestartGameObject window = (RestartGameObject) EditorWindow.GetWindow(typeof(RestartGameObject));
    16.         window.Show();
    17.     }
    18.  
    19.     void OnGUI()
    20.     {
    21.         GUILayout.BeginHorizontal();
    22.         if (GUILayout.Button("Re-call Awake and Start for GameObject"))
    23.         {
    24.             // Get all the components attached to this game object
    25.             var components = Selection.activeGameObject.GetComponents<Component>();
    26.  
    27.             // Iterate over the components and call their Awake and Start methods
    28.             foreach (var component in components)
    29.             {
    30.                 Type type = component.GetType();
    31.  
    32.                 MethodInfo awakeMethod = type.GetMethod("Awake",
    33.                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    34.                 if (awakeMethod != null)
    35.                 {
    36.                     awakeMethod.Invoke(component, null);
    37.                 }
    38.  
    39.                 MethodInfo startMethod = type.GetMethod("Start",
    40.                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    41.                 if (startMethod != null)
    42.                 {
    43.                     startMethod.Invoke(component, null);
    44.                 }
    45.             }
    46.         }
    47.  
    48.         if (GUILayout.Button("Delete and reinstantiate GameObject"))
    49.         {
    50.             // Get the original prefab for the selected game object
    51.             GameObject originalPrefab = PrefabUtility.GetCorrespondingObjectFromOriginalSource(Selection.activeGameObject);
    52.  
    53.             // Check if the original prefab is a prefab asset
    54.             if (originalPrefab != null)
    55.             {
    56.                 if (PrefabUtility.IsPartOfPrefabAsset(originalPrefab))
    57.                 {
    58.                     // Get the prefab asset path
    59.                     var prefabAssetPath = AssetDatabase.GetAssetPath(originalPrefab);
    60.                     Debug.Log("Prefab Asset Path:" + prefabAssetPath);
    61.                
    62.                     GameObject newGo = Instantiate(originalPrefab, Selection.activeGameObject.transform.position,
    63.                         Selection.activeGameObject.transform.rotation);
    64.                     DestroyImmediate(Selection.activeGameObject);
    65.                     Selection.activeGameObject = newGo;
    66.                 }
    67.             }
    68.             else
    69.             {
    70.                 Debug.Log("Not a prefab asset, so I'll just clone this one");
    71.                
    72.                 GameObject newGo = Instantiate(Selection.activeGameObject, Selection.activeGameObject.transform.position,
    73.                     Selection.activeGameObject.transform.rotation);
    74.                 DestroyImmediate(Selection.activeGameObject);
    75.                 Selection.activeGameObject = newGo;
    76.             }
    77.  
    78.  
    79.         }
    80.         GUILayout.EndHorizontal();
    81.     }
    82. }
     
  46. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Thanks, that's really cool to read! Getting out of the 'zone' is also huge factor why I've build this. I can't stand 10s interuptions every time. From time to time it gets me to some browser tab like mail and poof - concentration gone, time for coffee.

    I think you're right on Unity looking for fully-fledged solution. This is mainly hack that like you said ticks 80% of the workflow where it wouldn't be stable to go all-the way.

    But of it quacks like a duck... ;)

    Would be great to hear how you're getting on after you had a chance to look at it with students. We're on discord btw - probably best place to get support and fixes before they make it's way to the store, if you want to join - link is in 1st post.

    Thanks for the code at some point I'll extend the tool to allow bit more control for better iteration and it's possible something similar will make it's way in.

    Right now I'm looking at getting those limitations down. Mac / Linux already done and slated for release.

    Next on the list getting debugger support back in - which is actually looking very good!
     
    Last edited: Dec 30, 2022
    Vectrex likes this.
  47. friuns3

    friuns3

    Joined:
    Oct 30, 2009
    Posts:
    307
    1.1 Works now faster without delay!

    but found new problem after hitting play button and stop, i have 1 core full utilization, normally its 0%

    Taskmgr_1kbL7uCGGR.png

    I changed file watch path to scripts folder seems its fixed it
     
    Last edited: Jan 2, 2023
  48. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
  49. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    Live script reload is out! It allows for same hot-reload but on-device - like android APK or windows Exe

    It's a 5$ extension (as long as you have fast script reload already)

    You can get it on asset store

    Hope it's helpful!
     
    Vectrex likes this.
  50. ChrisHandzlik

    ChrisHandzlik

    Joined:
    Dec 2, 2016
    Posts:
    203
    v1.1 is also out. Comes with:

    1.1 - Mac support / bug fixes
    • Added Mac support (only INTEL editor version, SILICON still not supported)
    • Added Linux support
    • fixed namespace clash with Unity.Collections package
    • common code lib will not be included in builds
    • added check for auto-refresh in Editor - will proide guidance and option to adjust as otherwise full editor reload is triggered for changes
    • added workaround for Unity file-watcher returning wrong file path on some editor versions
    • added option to allow disabling DidFieldCountCheck - allowing to detour methods in those cases (eg for Mirror where it'll adjust IL and cause mismatch)
    • added option to configure FileWatcher paths/filters as in some cases watching root directory was causing performance issues
    • added minor initial-load optimisations - using session-state for items that do not need to be resolved on every reload

    And also just adding some notes on how to re-enabled debugger support till 1.2 is out with some better support.
     
    friuns3 and Vectrex like this.