#[Guide] Optimizing Long Compile times (Including multiplayer games)

1 messages · Page 1 of 1 (latest)

fair chasm
#

------------------------------------------------------
- Intro
------------------------------------------------------
[WARNING - Long post!]
For a really long time I have experienced slow compile times.
ranging from 1 minute per code-change to such big projects that took around 20 minutes to just play the game.

after a very long multi-year research, I finally managed to Lower the compile time from 1 minute per change,
to between 10(ms) to 4(Seconds) on my biggest Unity project. depending if in playmode or not.

I am writing this post to those in the future who will find it, also encountering such long compile times and would like to use Unity and build games fast without waiting for the editor to finish working.
I will try to put here all the solutions that I am aware of, hopefully this list will be long,
and of course helpful.

#

------------------------------------------------------
- List of solutions
------------------------------------------------------

#

-------------------------------- List of quick easy solutions: -----------------------------
these are quick fixes which are worth trying to boost the Unity Editor's performance

// clear registry
if you made lots of projects in the pass, your registry could be bloated with them.
even if you deleted them!
this step is dangerous, only do this if you know what you are doing!
doing this, will reset some unity-general settings for the editor on your projects. like the layout of the editor, which windows are placed where.
the actual project settings are saved inside your project folder, so don't worry.
search for REGEDIT on windows and open the registry editor.
navigate to Computer\HKEY_CURRENT_USER\Software and delete the following folders:
Computer\HKEY_CURRENT_USER\Software\Unity
Computer\HKEY_CURRENT_USER\Software\Unity Technologies
Notice: you can create a backup by rightclicking a folder in the registry, and clicking Export.

// windows defender
if you are working on Windows, go to the windows defender settings, virus and threat protection:
add to the "excluded folders" the following folders:

  • your project folder
  • the unity engine install folder
  • appdata/local/temp (yea, it improves by a bit when importing assets)

// Keep minimal background processes
when working, make sure to have as least open windows in the background as possible.
make sure your web browser is closed,
Exit steam (not just the window, but right click the steam Icon and click close)
and so on for any unessesary programs.
try going to the Task Manager and see what eats up your Ram, focus on those.

#

// Restart Unity / PC
if Unity was open for a while, it could cause performance issues. this was mostly fixed on Unity 6, but still worth doing from time to time.

  • close and open your unity project
  • restart your PC can also help.
    checkout in the Task Manager -> Startup what programs auto load after restart.
#

-------------------------------- List of recommended solutions: -------------------------
these take a while to do, but can be worth your time

// Moving to disk C
this gave a massive improvement for me.
move both the folder containing the editor installation, and your project folder to an SSD Disk containing your operating system.
this can take a while to do, but will improve compilation times significantly.

// Rebuild Library

  • close the Unity Editor
  • go to your project folder and delete the Library folder.
    it should be near your Assets folder.
    now open the project in the Editor, this should take a while to open since Unity is rebuilding lots of assets,
    but once it finishes it can sometimes boost compile times.

// Disable IDE Tools
some IDE's come with tools that run on the project's folders and can slow it down.
I recommend disabling those if you don't use them.
just don't forget about them as they can be very useful in the future.
For Visual Studio Community I disabled:

  • Entire project scan (I search all fiels with the regular Code Search feature)
  • Visual Studio Debugger (all of them)
  • Visual studio build debugger
  • Visual studio profiling tools

For Rider I disabled:

  • Roslyn (massive compilation boost!)
  • Applied a solution filter (this makes rider open up quickly and boosts refresh)

// Remove uneeded packages
visual scripting / AI / 2D Packages / Entities
are some very powerful packages that now In Unity 6 come auto installed.
I personally use AI and Entities, but most people don't (damn!)
I strongly recommend going over the installed packages in the pakcage manager and removing anything you don't use.
this can improve the time it takes to compile the general assembly assembly-csharp and in general when entering playmode.

#

-------------------------------- List of very powerful but considerable solutions: --------
think a lot about each step here. each one of those can improve compilation time
by a lot, but are dangerous if you don't know what you are doing.

// Assembly Definitions
I considered putting this first since it is important and very easy to do, just takes a while to learn.

Easy to learn, powerful when mastered

  1. split your code to system.
    e.g. combat system, Inventory system player system and more,
  2. for each system, put all code files in a folder, and Create a new Assembly Definition (.asmdef) file through the editor.
  3. configure it with the required references (Cinemachine, CombatSystem)
  4. make an asmdef for your main game and reference all the systems to it.
  5. profit. your code is now well orginized, and compiles faster than before!
    I strongly recommend watching a youtube video about these.
#

// Domain Reload
[Dangerous!] if you know what you are doing when writing code, you should give more focus to resetting static variables and unsubscribing from events.
if your project is built in a way where this is possible, go to your project settings and Disable Domaing Reload And Scene Reload.
this will improve compile times noticibly, but can cause unexpected behaviour if your code does not work with static variables correctly.
it will also require you to manually reload the scene every time you want to make any changes.
personally I recommend turning off only domain reload, and using as least static variables as possible. just do it smart, if you like your code it's probably at it's best. I believe in you.

// Hot / Fast Script Reload
this has improved compile times for me far more than anything else.
this requires disabling Domain Reload (from the previous step) to work.
Hot Reload is a way to make Unity Only compile new code, such as new functions or a new debug line.
so instead of compiling your entire project, it will only compile a small part of it.

this works by building only the small part you change to disk and smart-replacing only that part after the program is loaded into the memory.
there are some great plug and play ones from the asset store, and open source ones on github.
games like subnautica also built their own hot reload solutions using open source c# hot reload libraries.
checkout Harmony on github if that interests you.

I got one from the asset store, that supports both playmode and editor hot reloading. after doing this, (and all changes that were written here)
it takes me around 4(ms) to recompile when in play mode / debugging stuff, adding changes or removing general code,
and around 8 seconds to recompile (Actual full assembly definition compilation) when creating new files / classes or renaming existing files.

#

// How to upgrade your PC
well, this is usually the least available step but this will probably give you the biggest improvements.
when upgrading your pc, consider the following for Unity:
CPU: Unity uses only 1 Thread! yea, that's wild. but that's how it works. you don't need a super I7 Cpu to work.
you should get a strong cpu that has great per - thread performance!
I upgraded to a recent I5-14400 cpu, it works great.
RAM: from my expirience, upgrading this boosts times more than cpu.
I recommend at least 16gb ram and since you are going to have some web tabs open in the background and a brackeys tutorial, with discord asking for help and that AI window open, get at least 24gb RAM. I am using 32gb, which is exactly enough for me.
GPU: doesn't really matter, this will affect light baking and world creation, less important if you are mostly programming.
unless you are working with visual effects and entities - any decent GPU will work.

Multiplayer & Shared development

  • ParallelSync vs Play Mode
    if you are using netcode for gameobjects it's best to use the new multiplayer playmode package. if you are using a different multiplayer solution, parralelsync is a great option but is really really cost heavy.
    since the new UMPM package is still in beta, it can be buggy, and parralelsync would be the best option, and you would need lots of ram to make it work great.

  • Accelerator Server
    if you are working with other people on the same project, on the same network, look up on a Unity Accelerator server.
    this can help a lot to reduce iterations and build process!