Unity Project: From 3GB to 200MB

Unity Project: From 3GB to 200MB

Prologue

This Tutorial probably only works for Windows users
since Linux Shells and the Command Line on Mac have a different syntax than Windows cmd and the software AutoHotkey is only built for Windows.

What's the Problem?

There are many reasons for clearing the auto-generated Unity files.

You may want to share the project without sending GBs of data,
Something may have gone wrong with the internal caching from Unity or
Just want to keep unused projects in your pocket, but have them as small as possible.

I had roughly 34 currently unused Unity Projects worth 110GB lying around, which are now down to 60GBs.
The usual fix for this problem is clearing the Library and researching which files are auto-generated as well, which I learned from this video.

What do I need?

I wanted either an AutoHotkey shortcut, .exe or cmd command prompt to semi-automate that process.

CMD Approach
This command won't move the files into the garbage bin.

The Cmd Command will require you to open the cmd panel:

You will need a copied path of the Unity Project folder/Directory,
just navigate to it and click here:

To get this view where you can press strg + c

Here's the syntax to direct your cmd panel to a desired location:

cd (strg + v copiedPath)

This will look like this:

You can paste this shortcut in the cmd panel, which will delete all auto-generated files.

rmdir /S /Q Logs, Temp, Build, obj, Library & del *.sln *.csproj

rmdir - means remove directory and is used for deleting folders
/S - means that it'll delete all files in the folders mentioned
/Q - skips the safety question for each file (if you really want to delete it)
Logs, Temp, Build, obj, Library - are the folders we want to delete
& - Chains the next command
del - is for deleting single files
*. - tells the program to delete all files of the given type (sln and csproj here)

It can take a few seconds for the Library folder to be deleted since it's usually about 1,5 - 3,5 GBs large.

AutoHotkey .exe Approach

We will be using the AutoHotKey software as in my recent [SerializeField] blog post to create an .exe that does essentially what the command above does.

You'll have to download AutoHotKey and the ClearLibrary script (.ahk file) here.

Here's the straightforward syntax for the deletion:

FileRecycle, *.csproj
FileRecycle, *.sln
FileRecycle, Temp
FileRecycle, Build
FileRecycle, Logs
FileRecycle, obj
FileRecycle, Library
FileRecycle, ClearLibrary.ahk

File recycle takes all wanted types (folder and file type) after the "," and moves them to the bin.
It recycles itself at the end.
I've included a zipped version in the download since the script runs after activating (double-clicking it) and you could accidentally delete it in your download folder.

To prevent the ClearLibrary script from deleting itself after runtime,
if you for instance want to use it regularly in the same project,
delete the last line of code in the .ahk file using a text editor.

So How Effective Is This?

For reference, I'm using an MSI GP76 Leopard 10UE Laptop.

Here is an example of an almost empty 2D Project, where it cleared 1,47 GBs.

It takes 43 seconds to open without generating the files new.
It took 3:30 minutes to regenerate.

This is a fairly big 3D Project of mine, it cleared 5,37 GBs here.

Opening the Project took 48 seconds without generating files new.
It took 9:40 minutes to regenerate.

Conclusion

I consider both covered ways as fairly convenient to use.
It's worth saving that amount of storage for me,
especially when I'm not planning to open those projects for a long time.

Thanks for reading, take care!