General problem with scripts: The associated script cannot be loaded

Hi!

I have been working on a project for two weeks. All the scripts attached to any gameobject where working properly until, without any change made, all showed this error: The associated script cannot be loaded, please fix any compile errors and assign a valid script, even in Unity’s scripts like Camera Smoothfollow one…

There is not any compiling errors in them but i cant even see them in the component menu or drag and drop them in the inspector. I have tried a new project and the same scripts work properly.

I have tried reimporting all, I have installed Unity’s last version, i have rebooted my PC but the errors are still there. I cant execute the project in the inspector or build it in any way.

Has anybody notice the same issue. Any idea or suggestion is welcome.

Thanks.

16 Likes

SOLVED- I took all the scripts to a folder out of the project,deleted them, built project, reimported all the scripts from the backup folder one by one… And they were all working again. A bit weird but worked for me.

10 Likes

I got the same problem today, for the second time since i’ve using unity, I haven’t yet tryed to reimport all the scripts, but this is really annoying, so I have to do this all the time that happens? I think this have to be fixed as soon as possible!

9 Likes

I have the same problem. Suddenly the scripts stop working with the error: The associated script cannot be loaded, please fix any compile errors and assign a valid script. I didn’t change the scripts at all.
This is very annoying. But it seems there is no patch for this?

This is getting worse and worse… I don’t know what causes this, but when I tried to build my project, unity gave me errors on some scripts. I deleted all of them and when I built the project again, Unity gave me errors on totally different scripts. Scripts I not even used in my project.

This happened to me for the third time today! I did not even touch those scripts… Some of them are standard Unity scripts like Character Controller etc.

10 Likes

Was having the exact same issue when moving scripts in and out of the assets folder. To fix just delete ALL the meta files in the assets folder and reopen your project. Unity should rebuild all the script references. Also make sure to remove all compile errors.

5 Likes

first time using unity and I got this. Really new to unity first time working with 3d games. this is a huge turn off for new beginner. I was looking at the solve solution at the top but i don’t really know how to do that. where do i find the scrips to move them? then what do i delete? the scrips i moved or the project? and if you delete the scrips how do you get them back to import them again without have to re write them?

This happened when i was going through the learn project “stealth” at the first script for the game in Chapter 1 / 103 - Alarm lights.

any info on this would be great thanks!

8 Likes

Happens to me ateast once a week. Then it will suddenly go away.

1 Like

I had a similar problem. I realized it occurred because I had moved some scripts using the mono develop view. I just deleted all the scripts and copy pasted them from a backup. Unity imported all the scripts again and they were working normally.

Had this trouble, f*cking tired, but had decision. At script i renamed “public class …” where “…” - name of Script File.

4 Likes

[quote=“slagemer1, post:9, topic: 507105, username:slagemer1”]
Had this trouble, f*cking tired, but had decision. At script i renamed “public class …” where “…” - name of Script File.
[/quote] This doesn’t make sense.

14 Likes

Having the same issue. Also with the stealth tutorial project, having finished assignment 106. Finished the other tutorial projects without any hassle. Reimporting didn’t help yet.

Also deleting all meta-files didn’t help. There are no console errors.

I’ve also converted the scripts from UTF-8 to ANSI Coding, but to no avail.

OK. SOLVED: My bad. Filenames didn’t match classnames.

25 Likes

Im justing starting a new unity project it sais the associated script-cannot be loaded ive tried everything Help me pls!

This happened, tried some advice… Now all my scripts are completely gone… I’m so pissed…

1 Like

I had the same problem. For me, it was because the script filename did not match the classname. Renaming the script according to the class fixed it up. Moving the script might have a similar effect, which would explain why restoring them from a backup is effective. Good luck.

11 Likes

First you need to check to see if you class names are the same. (Without the .cs). Then you go into your main assets folder. Then you right click and hit re-import all. It might take a few hours but it gets rid of those errors!Sorry, i'm just testing out the code function.

2 Likes

I have this problem too, I’m on the 5.0 beta, the script comes from my compiled dll. when i assign it to a gameObject, it gives me a warning box, what are the actual reasons for making this happen? this hasn’t happened to me for a long while and right now its just showing up for some unknown reason…

EDIT: it was a bug… going into Inspector Debug mode and then to Inspector normal mode fixed the problem.

1 Like

This. I had overlooked it since most of my scripts are in Javascript.

2 Likes

If you have code inside a preprocessor #if statement that doesn’t compile even if that code shouldn’t be compiled for the current platform, you’ll get this error.

For example:

#if UNITY_ANDROID
    if(true { // syntax error here
    }
#endif

It’s hard to detect if your build platform is set to something else so the code doesn’t actually have to compile. Unity doesn’t report this as an error when importing the script, but it will break any references if this is a Monobehaviour and you’ll get the “Associated script cannot be loaded” error on play.

3 Likes

The class name and file name mismatch was the problem for me… It works when the two are matched…

6 Likes

What i found to be the problem was that I had built the project into a folder in the assets directory of the project that was titled Builds. I deleted this builds folder and ALL errors went away. I think this is the problem Unity is having so just make sure you are building your project to a folder outside of your project folder (like to your desktop or a folder in documents titled UnityBuildsBrah)