[RELEASED] Live Script Reload - (1. Play 2. Make change 3. See results) [editor and build]

Are you tired of waiting for full domain-reload and script compilation every time you make a small code change?

Me too.

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

Even better it’ll do that on device, be it to already running .exe or deployed Android APK.

Iterate on whatever you’re working on without restarting the app over and over again.

Works with any code editor.

Get It on Asset Store | Documentation | Discord

You can see fixes for current issues at the bottom of this post FAQ/FIXES section.

• Setup

  1. Import
  2. Create Build
  3. Play Build and Editor
  4. Make Code Change
  5. See results

It’s that simple.

• 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! :slight_smile:
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 visuble unless you make 100s of changes in same play-session.

• Supports (Tested)

  • Unity 2019.3
  • Unity 2020.3
  • Unity 2021.3
  • Unity 2022.2

• Breakpoints in hot-reloaded scripts won’t be hit

  • debugger still functional - easy workaround described in the docs
  • only for the scripts you changed, others will work

• 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
As with methods, adding new fields is not supported in play mode
You can however simply create local variable and later quickly refactor that out

• 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

  • this is in version 1.1 that’s yet not released - if you need mac support as above please get in touch once you got the asset and I’ll send you the update

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

• Roadmap

  • add debugger support for hot-reloaded scripts
  • better compiler support to work around limitations

• FAQ

1)
I’m creating Android build but it doesn’t work

When changing deployment platfroms please make sure that build symbol ‘LiveScriptReload_IncludeInBuild_Enabled’ is present. Go to Window → Live Script Reload → Start Screen → Options/Build. Disable and Enable ‘Enable Hot-Reload for build’ - this will force tool to re-add build symbol to settings. Issue will be fixed with next release.

2)
I’m getting ‘System.IO.FileNotFoundException’

Quite rarely there seems to be an issue happening with FileWatcher and resolving proper path.

As a workaround, please:

  1. go to ‘\Assets\FastScriptReload\Scripts\Editor\FastScriptReloadManager.cs’

And whole OnWatchedFileChange method to:

        private void OnWatchedFileChange(object source, FileSystemEventArgs e)
        {
            if (_lastPlayModeStateChange != PlayModeStateChange.EnteredPlayMode)
            {
#if FastScriptReload_DebugEnabled
            Debug.Log($"Application not playing, change to: {e.Name} won't be compiled and hot reloaded");
#endif
                return;
            }

            if (_currentFileExclusions != null && _currentFileExclusions.Any(fp => e.FullPath.Replace("\\", "/").EndsWith(fp)))
            {
                Debug.Log($"File: '{e.FullPath}' changed, but marked as exclusion. Hot-Reload will not be performed. You can manage exclusions via" +
                          $"\r\nRight click context menu (Fast Script Reload > Add / Remove Hot-Reload exclusion)" +
                          $"\r\nor via Window -> Fast Script Reload -> Start Screen -> Exclusion menu");
     
                return;
            }

            var changedFileName = new FileInfo(e.FullPath).Name;
            var fileFoundInAssets = Directory.GetFiles(DataPath, changedFileName, SearchOption.AllDirectories);
            if (fileFoundInAssets.Length == 0)
            {
                Debug.LogWarning($"Unable to find file '{changedFileName}' via FileWatcherBugWorkaround, changes will not be reloaded, please contact support.");
            }
            else
            {
                _dynamicFileHotReloadStateEntries.Add(new DynamicFileHotReloadState(fileFoundInAssets[0], DateTime.UtcNow));
            }
        }

3) My editor does full recompile / reload on every 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)

I’ve got a few vouchers (0 left) to share.

Please reply if you’d like to try it out!

Update: sorry all vouchers are out

This seems awesome, would love to try it out experimenting with ball trajectories in my VR Cricket game, i’d love a code <3

Thanks, that’s cool - one’s on the way!

Would be great to hear how you’d got on.

And if you need any help, discord is usually fastest.

Hey,

I am the one who asked on the reddit thread about student licenses.
Would appreciate something like that.

cool - check your PMs :slight_smile:

Hi. Do you have a voucher for it? Thanks. Happy new year.

Hi, sure. It’s in your mailbox! Thanks

Some users have reported minor issue when using VSCode

VS Code proj file (csproj) generate with NetFramework version 4.7.1. One of the plugin DLLs is targeting version 4.8.
Even though VS Code does not compile that code (Unity does) - it’ll still show error as it didn’t load the library for code-completion.

It’s not a plugin issue as such, other dlls will have same troubles.
Best solution I’ve found is to force csproj files to be generated with 4.8 version instead.
This can be achieved with following editor script

using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

public class VisualStudioProjectGenerationPostProcess : AssetPostprocessor
{
    private static void OnGeneratedCSProjectFiles()
        {
            Debug.Log("OnGeneratedCSProjectFiles");
            var dir = Directory.GetCurrentDirectory();
            var files = Directory.GetFiles(dir, "*.csproj");
            foreach (var file in files)
                ChangeTargetFrameworkInfProjectFiles(file);
        }

    static void ChangeTargetFrameworkInfProjectFiles(string file)
    {
        var text = File.ReadAllText(file);
        var find = "TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion";
        var replace = "TargetFrameworkVersion>v4.8</TargetFrameworkVersion";

        if (text.IndexOf(find) != -1)
        {
            text = Regex.Replace(text, find, replace);
            File.WriteAllText(file, text);
        }
    }

}

As a one-off you may also need to go to Edit → Preferences → External Tools → click ‘Regenerate project files’ buttons

First off, I want to say that this is awesome. Unity should flat out hire you. I’ve been dreaming of hot-reload in Unity for forever. I know it isn’t a full domain reload, but I don’t care, I just need my developer cycles to be faster.

Have you by chance tested this with “dedicated server” / headless builds (for servers) yet?

Thanks - glad you like it!

You mean to adjust code in a exe that runs dedicated-server build (no graphics)?
If so I’ve not tested it but it relies on networking and assembly load, so shouldn’t be an issue to hot-reload.

Not 100% sure if I understood you right though.

Yes, on dedicated server. My usual flow is that I run my server as a build and then the game client is in my editor, hit play and do some testing. When I need to make changes, I mentally have to keep track if I will need to rebuild and restart the server on each change. My hope with hot reload would be that the client and server both can pickup on the changes at the moment I change them.

Alright, yeah - that’s possible. Right now editor will only allow 1 connection though (so you won’t be able to connect both client and server to same editor session).

The only reason for that was simpler ux / code initially so it’s quite straight forward to change.

I’ll try to add it and will let you know once in.

If you want to have a look yourself, it should be in classes that implement networking. I think if you look in AssemblyReceiver (sorry can’t remember exactly, but there’s just 2 classes that deal with network) - you’ll find it limited to single connection.

Debugger support is coming in v1.2 - that’s now submitted to asset store.

Should be few days but if you can’t wait just get in touch with me on discord and I’ll get you the release early!

1.2 with debugger support is now out :slight_smile:

With 1.3 I hope to add some experimental support for adding new fields that show in editor - so you can use them same way that you would normally. But of course without breaking play-session :slight_smile:

1 Like

Hi. Do you have any voucher for it? I am very intrested and curious to check it out. I would really appreciate it!.
Thanks!

@mubashirirshad sure, check PM :slight_smile:

Playmode added fields that you can tweak in editor looking very good so far. Hoping to get the release out next week!

If you still have vouchers left, I’d love to test this out :hushed:

I’m sorry @Lothar I’m all out but Fast Script Reload is on 50% sale, once you got that one - this one will become 5$ upgrade so you get it for 20$ instead of 35$. Hope that helps a bit!

1 Like