Search code examples
c#unity-game-engineunity-editor

Multiple script and namespace errors on a previously working Unity project . Type or namespace name 'GUIColorOverride' could not be found


I had some unusual errors on a relatively small Unity project with six c# scripts written in Visual Studio. It was all working fine, and I came back to it after the weekend. Upon opening, there were 18 new errors which were preventing the code from compiling and I spent several hours trying to figure out what was going on.

The main errors were saying things like Type or namespace name 'GUIColorOverride' could not be found and associated script cannot be loaded, assign a valid script, even though they were linked and I could see the scripts had no errors in Visual Studio. I even did a full Unity uninstall and rebooted, then a clean install. This didn't fix it.

I tried a number of other things such as backing up the scripts from the assets folder and then deleting them. Opening the project and pasting them back in as 'clean' new scripts. This didn't work. I am using Unity's Cloud Collab so was even able to use this to go back to earlier pushes of the project (which had all worked). Nope.


Solution

  • You should exclude these from the Backup!


    Basically you can exclude anything that would also be excluded from git via e.g. this "official" .gitignore file for Unity projects.

    Any file and folder listed here will be regenerated by Unity automatically and should not appear in any version control / Backup.

    The entire Library folder in particular is part of it since its content changes quite rapidly and is recompiled every time you change a script, install/remove a package etc.

    Checkout Unity Manual - Behind the Scenes for more information in detail

    When backing up a project, or adding a project to a Version Control Repository, you should include the main Unity project folder, containing both the Assets and ProjectSettings folders. All the information in these folders is crucial to the way Unity works. You should omit the Library and Temp folders for backup purposes.


    To solve an already present issue with the Library folder you can most of the times fix it by simply closing Unity, deleting the entire Library folder via your file browser and opnening Unity again → Unity will rebuild the Library