2019.4.40f1 editor extreme lag that was not there before, lag after each script save

Hello,

To briefly explain my issue: I’m experiencing a very big inconvenience with a lot of lag after every script modification. This has not been an issue before, and started happening after one of the Unity restarts.

In more detail:
I have been working on a project for several years now and haven’t encountered this problem. I have not updated Unity (I can’t really, I think 2019.4 is the farthest I can go due to some dependencies) any time recently, the only “update” that I had was a Windows Update 3 days ago or so (and a manual one yesterday). It’s unclear when exactly the issue started happening because I haven’t been using Unity two days ago as much as I have been yesterday.

The thing is it would be normal for Unity to freeze here and there for like, 5-10 seconds max after a script change. However 3 minutes + is definitely out of the ordinary, especially since this happens after every save. I have a really good set up as well, with 32gb RAM, i9 CPU, RTX 3070, lots of free disk space, etc.

Things I’ve tried:

  • Removing all my external drives, USBs, etc.
  • Deleting the library folder and allowing unity to rebuild it
  • Deleting some packages that might have been causing issues (either way nice to clean up those)
  • Using notepad instead of Visual Studio (it’s definitely not a VS issue I think)
  • Saving on a different script
  • Saving on a different scene
  • Rebuilding project files (for external editor, VS)
  • Deleting temp folder
  • Reimport all (This step takes a really long time because I have several GB of assets in this project)
  • Disabling auto refresh (don’t like it either way because I like the code changes applied so I can go to playmode quickly), but it would just cause the same issue right before playmode
  • Did sfc scan, memory scan (mdsched.exe), a bunch of other health checks. Though my computer seems fine and perfectly functional, only Unity is suffering
  • Restarted windows several times
  • Disabled analytics in privacy settings

Interesting things I’ve noticed:

  • Profiler doesn’t really show anything special, at least as far as I know. I think the most notable is either Application.Message or Application.Tick
  • Saving a shader doesn’t have this problem at all! I’m assuming it’s a cs code compilation problem so the shaders are excluded
  • Unity doesn’t freeze up when importing non code assets (besides the regular import times)
  • Going into play mode outside of these script saving lag times is perfectly normal and fine
  • I tried reinstalling Unity 2019.4.40f1
  • This bug seems to exist now on other projects, as I went to a previously perfectly fine (and way smaller) project that is now taking a long time, and it’s not even the same Unity version
  • This might be related to Windows Update as I only started noticing it since an update 3 or 4 days ago.

It’s worth noting again that I did not update Unity or anything Unity related when this bug started happening. I’d really love any help, as usually posting on forums is my last resort. I will continue trying in the meantime, but any help is greatly appreciated.

Thank you!

Hmmm … I can’t find “rolled back to previous project version in source control” in your list. :wink:
If an earlier project version doesn’t have the issue all it takes it to look through the changes made in between and depending on the granularity of commits it should be easy to find the culprit.

I’m also not seeing anything related to installing or removing software. You may think you did not change anything, but maybe you did and can’t remember? I wouldn’t know for certain whether I installed a new software yesterday either. You could look through the Windows restore points to see at which dates/times something got installed - this might either be an update or a software, or some other software’s update.

Make sure to exclude the project and Unity folders from virus and other file system scanners. And close all background apps.

Profiler: did you enable deep profiling and edit mode?

One thing you should test: open the project, then open the editor.log and clear & save it. Then make a script change, wait for compile to finish, and look in the editor.log. This may reveal some useful info, if not actual timings. If you find that there’s a lot of things going on, even assets being imported, I’d suspect editor scripts. There are so many badly written editor scripts out there, it’s unbelievable and has more often than not caused slowdowns in my projects.

More tips for broadly excluding possible causes:
You could check if another project, or a new one, exhibits the same issue. If it does, it’s more likely a system or hardware issue (failing disk drive, or CPU overheating and thus throttling - though you’d feel those in other situations too).

Since you seem to be having several external drives, perhaps install Windows on one of them to see if a fresh install fixes the issue. If not, you’d either have to consider a hardware issue or, rather likely, something within the project itself.

Hello,
Thank you for your reply! I’ll try to answer things in order…

I don’t use source/version control, I just have local and cloud backups. But funny thing is, the last backup I did was just 4 days ago or so… in between then and now, I only pretty much added one shader change, and one script. Neither are too special either, as especially the script is pretty much the same as a lot of other scripts I have (extending from a certain class I use for a lot of other classes).

My antivirus settings haven’t changed much, but I wouldn’t be surprised if that was the case. I didn’t see any flags in recent history there though so shouldn’t be that I think… I also have tested several times on a brand new restart with background processes closed.

I did enable deep profiling and set it to edit mode yes, unfortunately not much detail besides the things I mentioned (application.tick and application.message seem to be offenders but it’s hard to tell)

About the editor.log, I definitely haven’t tried that, and it gave me something very interesting…
ImportAndPostprocessOutOfDateAssets: 49213.358ms (4614.453ms without children)
I wish it told me more, but I at least know exactly what step takes such a long time. I’ll continue looking into this for now but just wanted to share my findings so far.

I tried opening another Unity project just now which uses version 2021.3.11f1, and funny enough that also took a crazy amount of time (ImportOutOfDateAssets: 78581.860ms (2677.408ms without children)), despite being a much smaller project! But at the same time, it doesn’t feel like a memory issue or CPU issue, since I have ran several other programs within this time period without issue.

And lastly about the drives, I’d like that as a last resort… since reinstalling windows is an even bigger pain. I’d like to see if there are other options before resorting to that, especially since this seems to only be an issue with Unity.

Did you run the older backup? Does it have the same issue or not? If not, you could still “diff” (using tools) the two projects, at least the Assets and ProjectSettings folders to see what other changes there might have been made, possibly automated.

They change on a daily basis as antivirus updates are sent out on a daily basis or even more frequent. Disable antivirus for a quick test.

Oh yeah … I’d definitely focus on editor scripts. Check everything that hooks into typical domain reload events, from InitializeOnLoad to AssetPostProcessor and the like. Perhaps something triggered a script that now creates new assets whenever a script gets compiled, or needlessly calls AssetDatabase.Refresh and possibly repeatedly during domain reload events.

It could also be related to, or triggered by, an asset simply by changing the source asset or an import setting for that asset, which might have triggered subsequent (costly) processing.

Well, I could download the project, but it is over 50 gb for some reason and I unfortunately have forgot to make a local backup this time :frowning:
I can start the download at least. However I did try the project settings folder before, to no change though.

I excluded the Unity folder in program files and my actual project folder now, but still no change.

I’m just not sure, how would I check this? I tried things with the profiler, but it’s strange and doesn’t actually seem to tell me much. The spikes are inconsistent and say nothing about compiling either. I didn’t write any custom editor scripts myself, but don’t think I introduced any in a long while either, so not sure how I’d start about this.

While that may be the case, how would I be able to diagnose this? I tried to do the reimport assets option already before too, but it didn’t seem to fix things unfortunately.

One thing I forgot to mention, I also reinstalled Unity 2019.4.40f1 a few hours back, and it didn’t do anything. I also updating my VS 2019 to a newer 2019 version, and that still didn’t help (though I don’t know why VS would be the issue in the first place).

Reinstalling is sort of like a cargo cult thing, some esoteric concept almost if it wouldn’t actually fix some broken app in very rare cases (ie when the virus scanner was just being a prick). :wink:

Diagnosing this is practically a search in files (*.cs) to find any code that may trigger an asset reimport, most notably AssetDatabase.Refresh. Then check if that’s necessary - specifically Refresh is often just appended to asset scripts even though it need only be used if you had been modifying the file system directly. Of course there could also be the case where the file system does get modified externally. And asset postprocessor or importer scripts that modify assets during import, which could cause a recursive cycle of re-imports.

Another way to debug this is to make a copy of the project, and start trimming it. Remove any slack that doesn’t cause compile issues (or temporarily fix those) to see if the issue suddenly goes away - then you only need to look at the stuff you’ve just removed. Of course you need to start over from there and just remove that last part or scan its code thoroughly.

Yeah I understand, reinstalling is a coin flip haha

I was going to do what you mentioned first, but then I did something else and unfortunately it just keeps the situation at the same confusing point as always. I decided to make a brand new project, no package imports or anything, on the 2019 version. Made one script with a debug.log line and… 2+ minutes to compile. It makes no sense! I feel crazy at this point.

If I reinstalled Unity editor, what else could possibly be causing unity, on both versions I tried and all three projects I’ve tried, to behave like this? I’m currently thinking myself and will keep experimenting, but so far nothing still. I even uninstalled all updates within the past 5 days, and that didn’t fix the issue either.

EDIT: Tried to compile the super small test project again but it got fast all of a sudden, went back to other project and it got slow… just going to try to do bit by bit package migration and see what happens. Very confusing issue

Okay so, the issue was fixed, and it’s one of either two things:

  • Updating NVIDIA graphics card driver
  • Deleting unused packages (terrain tools, pro builder, analytics, ads which I don’t even know why I had in the first place)

Weird thing is though, I’m willing to bet on the NVIDIA driver. Since I said this happened with other projects as well, and I didn’t actually introduce any new packages, I think after Windows updated it hindered the interaction between Unity and the driver, even though everything else worked fine… oh well, at least I cleaned up some packages anyways haha

either way, thank you CodeSmile for helping :slight_smile:

1 Like

You’re welcome, glad you got it resolved! My next advice would have been: reinstall. Not Unity, Windows. :stuck_out_tongue:

But it kinda makes sense that uninstalling unused packages speeds up compilation, after all there’s plenty of scripts in them. You could double check this in the new empty project that gave you 2+ minutes compile time.

Btw, I always recommend using the Nvidia “Studio” driver over “Game Ready” because working in Unity is the studio driver’s recommended use case of “creative work” where you want the most stability and no performance-enhancing driver tricks.

1 Like

Thank you very much. I encountered the same problem and now it has finally been resolved. It is indeed because of NVIDIA graphics card driver.

1 Like

Anytime, glad I could help! Drivers and Windows are an evil combo sometimes haha