Blog / Unity

Managing Unity's Library Folder

The Unity Library folder holds a cache of imported assets, compiled scripts, and other temporary data, but it does not contain any important assets.

Managing Unity's Library Folder

Avoid Version Control Inclusion: Exclude the Library folder from version control systems like Git or SVN. Including it can lead to unnecessary bloat and potential conflicts. Github provides the latest .gitignore file suggested for Unity projects.

Unity .gitignore Example (Short version)
# Unity generated folders
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
# Autogenerated VS/JetBrains Rider files
.vscode/
*.csproj
*.unityproj
*.sln
*.user
...

Safe Deletion: You can safely delete the Library folder when the project is closed. Unity will regenerate it upon reopening. This is a common technique to resolve issues. Whenever you encounter package-related compilation issues, you may try to reload said packages in the editor, delete the PackageCache folder, or the Library folder entirely.

Unity Version Upgrades: Upgrading Unity to a newer version often changes how assets are processed. Keeping an old Library folder before a version update can cause errors and leaves unused data behind. We recommend deleting it before major version upgrades to avoid compatibility issues and to reduce the amount of unused data in it.

Note: The same should be done by all team members when they pull commits with major changes.

Regular Maintenance: Periodically clearing the Library folder can help resolve persistent issues and ensure a cleaner working environment. Sometimes the Library folder can grow in size and be a multiple of your Assets folder, especially if you delete and import many assets. However, be prepared for longer loading times after deletion as Unity rebuilds the cache.

By effectively managing the Library folder, you can optimize your Unity project's performance and save on disk space.

We analyzed around 80 of our Unity projects using a simple Python script. This resulted in a total of 128GB of Library data, most of which we won’t need anytime soon. This can quickly become a problem, especially if you're working on laptops and frequently starting small projects. On average, each project contained 1.5GB of Library data!

One real client project particularly caught our attention: the Assets folder was only 180MB, but the Library folder was over 3GB. This is mainly due to builds to different target platforms, such as Android builds.

Yes to Unity Cache Cleanup! We’re currently considering developing a tool that lists Unity projects and can (automatically) perform cleanup when needed. Why doesn’t Unity Hub have a feature like this? Do you like this idea, or does something similar already exist?

Read more about these topics: Unity