Every project/editor is broken for me! I can't code anything at all for any project.

Update - Selecting the exact script and clicking Edit → Reimport appears to cause the recompile. Eventually learned ‘Fast Script Reload’ disables auto refresh in every project not just the project that it is in. Need to re-enable ‘Auto Refresh’ in preferences.

I currently have an issue where I cannot get my scripts to recompile after editing them in an outside editor (including notepad). The only clue I have is it seems to be doing something where it believes my code doesn’t compile correctly. When I come back to editor it does nothing. But then when I do ctrl+b it gives this error.

Type '[Assembly-CSharp]NewBehaviourScript' has an extra field 'fieldThatIAddedAfterOpeningTheProject' of type 'System.Single' in the player and thus can't be serialized
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler ()
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
public float fieldThatExistsBeforeOpeningProject;
public float fieldThatIAddedAfterOpeningTheProject;
}

This is happening for every project including working projects I’ve had in the past as well as projects that I create brand new.

Scenario: Brand new project with zero changes 3D

Yesterday

  • Add Script
  • Change code
  • Come back to editor
  • Code Compiles - Like everyone would expect

Now:

  • Add Script
  • Change code
  • Come back to editor
  • Nothing at all! - Ever! in any project.
  • Inspector shows old code (I’m 1000% sure I saved many times and saw this every time)

Thank you for taking the time to read and help me with this issue.

I TRIED and didn’t work:

  • Installing an updated editor,

  • Restarting my computer,

  • Creating a new project from scratch,

  • Going in to old projects,

  • Clicking play,

  • Clicking Ctrl + b on empty project except my one script,

  • Treats the script that changed like it has a compile error (above)

  • If I remove the new code and put it back to how it was when I opened the project it builds fine.

  • Preferences → Script changes while playing → Recompile and continue playing.

  • Adding Fast Script Reload to a brand new project hoping that that it would just reload the code. (Fast Script Reload only affects play mode though so that’s why this did nothing)

Update a complete uninstall of every editor and unity hub and the unity folders along with the unity downloads folder and also deleting every unity folder in AppData did not resolve this issue.
I forgot to mention in the first post but I also tried multiple editors including notepad.

Well first get rid of the simple noobie typos… for instance, you would NEVER normally leave an unrenamed script such as this one:

See below for more notes on typos such as the above.

Beyond that, how to troubleshoot build failures:

First, make a blank project with a single blank scene and prove that it builds successfully.

If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

Until you can build a blank project to the target platform, don’t fiddle with anything else.

Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

Most often things that prevent building are third-party libraries such as Firebase.

Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

Android build not building:

Recently (circa July 2022) there have been reports of Unity’s installer failing to install the Android Tools.

https://discussions.unity.com/t/887277

Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022:

https://discussions.unity.com/t/891017/7

Android Gradle errors and other related stuff:

https://discussions.unity.com/t/901712/2


As for the typos in the first place, tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Finally, when you have errors, don’t post here… just go fix your errors! Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

@Kurt-Dekker I can see now I probably created too much text and might not be clear on a first read. But to be more clear I’ve been a unity developer for a long time and have made many successful projects. I was in the middle of a project that was working until one day it stopped recompiling and this issue happens to all installs of unity and all projects.

The ‘NewbieCode’ above is what is often called an MRC or “Minimal Reproducible Case”. The idea was to show that even in the most simple scenario that I could reproduce the issue. Everything I said was happening was working the day before.

Fair enough… if I was faced with what you describe, I would agree that this is pretty mysterious.

Since you have reinstalled the Unity Editor already, the only thing I can think of is some Microsoft runtime DLL getting corrupted on your machine so that Unity fails to run or fails to be able to observe directories.

What about Windows Update? Did something update last night on your system? I know there’s a log of updates somewhere and sometimes they can be unrolled / reverted.

Check preferences, like is Auto Refresh on? Directory monitoring? Also do Editor logs say anything around the time it supposed to recompile?

Also if you’re on Windows, it worth the try to step into the registry and clean that up also (especially when you perform a full uninstall-reinstall cycle). Just be careful, obviously.

@Kurt-Dekker Thanks for your help. I apologize for the initial wall of text I should have made that post much shorter. (I shortened it a bit for anyone searching on google later)

I did figure out the issue. I opened an old project to look at some prefabs as reference and it contained an asset named ‘Fast Script Reload’ The issue is that on startup it shows a dialog that says it will fix script reloading for you. It does that by setting this.

Preferences → Asset Pipeline → Auto Refresh → Disabled.

The problem being it sets that in every other project as well. It’s odd because it even breaks the project with Fast Script Reload if you actually choose that option. But pulling the project down caused it to ask me again.

@ I only was able to see your reply after hitting post. You hit the issue right on the head thanks for the post and good eye.

I’m pretty surprised that a full uninstall including deleting everything in %APPDATA% related to unity didn’t fix this though. Obviously they are just stored somewhere I was unable to find when looking how to clean uninstall online.

3 Likes

Preferences → Asset Pipeline → Auto Refresh → Enable.

It work, thank for sharing!

Thankssss so much. I was struggling with it for 2 days