How I fixed a Unity project that got stuck loading forever when opening a C# script

How I fixed a Unity project that got stuck loading forever when opening a C# script

Recently, while working on one of my projects in Unity, I opened one of my C# scripts, and… my Unity Editor decided to get itself stuck on the loading screen for a really long time. This led me to search online for a fix, and it took me quite some time.

Unity Editor infinite loading bar
The dreaded infinite loading bar.

If you’re experiencing the same issue, this article is for you. Hopefully, you won’t take as much time as I did to fix this error.

Here are some possible causes for your Unity Editor getting stuck on the loading screen:

  1. Your Library folder has very large files
  2. Check if the project folder is stored in OneDrive
  3. Uninstall the .NET Core SDK
  4. Afterword

Article continues after the advertisement:


1. Your Library folder has very large files

A Unity project that you open from the Unity Hub is actually just a collection of files and folders. The Library folder is one of these folders, and it primarily serves as a cache that helps to speed up the loading of your project over multiple uses.

Fun fact: If you’ve got your projects hosted on Plastic SCM, or if you follow our guide to host your Unity projects on GitHub Desktop, you will notice that the Library folder is also excluded from being uploaded onto the project repository. This is because, being a cache, Unity will automatically regenerate it when you load the files on a different computer. Hence, there is no point in uploading the Library folder, as it does not help to speed up loading times for other users.

For various reasons, files in your Library folder may have become bloated (i.e. extremely large in size). This may be causing Unity to crash when you try to open a C# script.

a. Finding your project folder

To fix this issue, you will need to first find and open the project folder of your Unity project. There are a couple of ways to do this, but the easiest way is to right-click on your Project window and click on Open in Explorer (or Open in Finder for macOS users).

Opening your project folder from Unity
Right-click anywhere in the project folder and select Show in Explorer.

b. Searching for large files

Once in there, head into the Library folder, then search for and delete for files that are extremely large, i.e. anything over a gigabyte (GB).

The Library folder
The Library folder.

A file that frequently has a large file size in Unity projects is the ShaderCache.db file, so that is one of the first few files you want to check.

The ShaderCache file is a common culprit.
The ShaderCache.db file is a common culprit.

Article continues after the advertisement:


c. Using a search filter to find large files (Windows)

An easy way to filter your Library folder for large files on Windows is to go to your search panel on the top-right corner (from your Library folder), then type in size:gigantic. This will find you all files that are above 128 megabytes (MB) in the folder.

Finding gigantic files in your Windows folder.
Finding “gigantic” files in your Windows folder.

If you can’t see file sizes in your Windows Explorer, you can have a look at this article on how to turn on the file size column in your Windows explorer.

d. Using a search filter to find files by file size (macOS)

If you’re on a macOS, you can also filter files in your Library folder by file size, but the process is a little different. Once you’re in your Library folder on Finder:

  1. Activate search by pressing + F.
  2. After the Search: label, select the "Library" label.
  3. On the dropdown, select File Size and type in the size of the file you want to find.
Filtering files by file size in Finder
Filtering files by file size in macOS Finder.

e. Deleting the whole Library folder

If you want to skip the entire process of finding these files, you may also delete the entire Library folder, but Unity may take a long time to regenerate the Library folder the next time you use the Unity Editor.

This should solve the problem. If not, or if you can’t find any large files, proceed to the next solution.

2. Check if the project folder is stored in OneDrive

OneDrive (for Windows) can cause issues with Unity projects. To check if your project folder is stored in OneDrive, open your project folder in the File Explorer. Folders managed by OneDrive have a “status” column, as seen below:

How to know if your folder is in OneDrive
How to know if your folder is in OneDrive.

If your project folder is managed by OneDrive, you’ll need to move it out of OneDrive or disable OneDrive. This should resolve the issue.

If your Desktop or other personal folders are in OneDrive, you may also find the following article helpful to unlink these folders permanently from OneDrive:

It may be worth noting that other cloud storage services such as Google Drive can also cause the same issue so you may want to check for other cloud storage services that may affect your project folder.

If your issue is not resolved after this, another thing you can try is to…

3. Uninstall the .NET Core SDK

The cause of the issue could be due to certain SDK versions. The issue may be resolved after you uninstall the .NET Core SDK by following this guide.

If this solution does not work, or if you encounter problems with Visual Studio after this, you can try running the Repair option in the Visual Studio Installer to get things back to normal. To do this (on Windows):

  1. Go to Start and search for visual studio installer. You should find an app called Visual Studio Installer.
  2. Click on the More button, then click on Repair. After that, follow through with the process.
Repair Visual Studio installation
Follow through with the prompts after clicking on Repair.

4. Afterword

I hope that this article has helped you in some way. Although it seems simple, this issue can be frustrating to solve. If none of the solutions worked for you, it will be great if you can leave us a comment to tell us how you fixed it.

If I have missed anything in this article, or if you have found other solutions you would like to share for people running into the same issue, please leave us a comment below too, as it may help others with the same problem as well!


Article continues after the advertisement:


There are 2 comments:

  1. thanks this was giving me a headache today, after searching for ages i found your post cheers. It was the onedrive setting i had changed causing my unity to crash

Leave a Reply

Your email address will not be published. Required fields are marked *

Note: You can use Markdown to format your comments.

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.

This site uses Akismet to reduce spam. Learn how your comment data is processed.