Search Unity

General problem with scripts: The associated script cannot be loaded

Discussion in 'Editor & General Support' started by Zape, Jun 12, 2013.

  1. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    10
    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.
     
  2. Zape

    Zape

    Joined:
    Jun 12, 2013
    Posts:
    10
    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.
     
    amgnewphone and MrMeows like this.
  3. Aleshotgun

    Aleshotgun

    Joined:
    Jan 12, 2014
    Posts:
    4
    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!
     
  4. LordDarkmoon

    LordDarkmoon

    Joined:
    Mar 7, 2014
    Posts:
    6
    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.
     
    Last edited: Mar 7, 2014
    jamieholt, ice2011, yoyo696 and 3 others like this.
  5. yummybrainz

    yummybrainz

    Joined:
    Jan 14, 2014
    Posts:
    65
    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.
     
  6. LegacyOfWax

    LegacyOfWax

    Joined:
    Jun 12, 2014
    Posts:
    11
    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!
     
    Jaqal likes this.
  7. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Happens to me ateast once a week. Then it will suddenly go away.
     
  8. isj126

    isj126

    Joined:
    Jan 3, 2014
    Posts:
    1
    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.
     
  9. slagemer1

    slagemer1

    Joined:
    Aug 13, 2014
    Posts:
    12
    Had this trouble, f*cking tired, but had decision. At script i renamed "public class ..." where "..." - name of Script File.
     
  10. iChealseaSmileU

    iChealseaSmileU

    Joined:
    Aug 13, 2014
    Posts:
    1
    This doesn't make sense.
     
  11. RedUnityCat

    RedUnityCat

    Joined:
    Aug 19, 2014
    Posts:
    1
    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.
     
    Last edited: Aug 22, 2014
  12. NLFUN204

    NLFUN204

    Joined:
    Nov 19, 2014
    Posts:
    1
    Im justing starting a new unity project it sais the associated script-cannot be loaded ive tried everything Help me pls!
     
  13. ASTERWOLF

    ASTERWOLF

    Joined:
    Jul 25, 2014
    Posts:
    3
    This happened, tried some advice.. Now all my scripts are completely gone.. I'm so pissed...
     
    DaCommanda likes this.
  14. MrGrieves

    MrGrieves

    Joined:
    Dec 6, 2012
    Posts:
    1
    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.
     
  15. sakyum70

    sakyum70

    Joined:
    Dec 23, 2014
    Posts:
    1
    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!
    Code (CSharp):
    1. Sorry, i'm just testing out the code function.
     
  16. ayanpike

    ayanpike

    Joined:
    Nov 23, 2014
    Posts:
    2
    this is utter bull S***. UNITY FIX YOUR CRAP OR LOSE ALL YOUR CUSTOMERS.
     
  17. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    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.
     
    Last edited: Jan 24, 2015
  18. miltonsegura

    miltonsegura

    Joined:
    Nov 23, 2014
    Posts:
    1
    This. I had overlooked it since most of my scripts are in Javascript.
     
    paperpancake likes this.
  19. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    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:

    Code (csharp):
    1. #if UNITY_ANDROID
    2.     if(true { // syntax error here
    3.     }
    4. #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.
     
    rpopic2 and shkar-noori like this.
  20. poetoaster3006

    poetoaster3006

    Joined:
    May 5, 2015
    Posts:
    23
    The class name and file name mismatch was the problem for me.. It works when the two are matched..
     
    virtuos-one and UnityX19131 like this.
  21. whitechili

    whitechili

    Joined:
    May 26, 2015
    Posts:
    1
    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)
     
  22. SaltyDog

    SaltyDog

    Joined:
    Apr 10, 2013
    Posts:
    1
    RedUnityCat has provided the solution. Check your file names against your class names. Worked for me immediately. I created a script PlayerMovement and renamed it PlayerController, but the PlayerMovement class name remained.
     
    virtuos-one likes this.
  23. jtonyhdz

    jtonyhdz

    Joined:
    Jul 31, 2013
    Posts:
    3
    Hi everyone!

    I solve this problem opening the Console window manually, there you can see the errors that are causing the problem, fix them and the auto compiler will work again.
     
    blairhoughton likes this.
  24. kervie24kervie

    kervie24kervie

    Joined:
    Oct 6, 2015
    Posts:
    1
    I hope this will help.. I also got that problem. I just reimport all assets and then it works again.
     
  25. KanraTaro

    KanraTaro

    Joined:
    Nov 29, 2015
    Posts:
    1
    This. I did this and my problems were solved, even a couple of bugs I didn't know how to fix were solved too!
     
  26. martin2016

    martin2016

    Joined:
    Dec 26, 2015
    Posts:
    2
    check your filename script and public class.

    Example for fixing error : filename script is "player.cs" and public class player : MonoBehaviour {

    not >> filename script is "player.cs" and public class planton : MonoBehaviour {
     
  27. martin2016

    martin2016

    Joined:
    Dec 26, 2015
    Posts:
    2
    check your filename script and public class.

    Example for fixing error : filename script is "player.cs" and public class player : MonoBehaviour {

    not >> filename script is "player.cs" and public class planton : MonoBehaviour {
     
    paperpancake likes this.
  28. D7Torres

    D7Torres

    Joined:
    Mar 3, 2016
    Posts:
    3
    For me, correcting an error in the script did the trick.
     
    TGMstudios likes this.
  29. ZapharaArts

    ZapharaArts

    Joined:
    Mar 25, 2016
    Posts:
    1
    This information may be helpful if you are stuck. I am new to Unity and was having problems with scripts that appeared to compile fine but gave errors that they had compile errors when I tried to run the project. I copied the project and removed all scripts, adding them back one by one until I found the problem script and then had to go through the code until I found the problem line.

    In my case, it was a struct with a parameterless constructor of this format:

    public struct TestStruct
    {
    int x;
    public TestStruct()
    {
    x = 0;
    }
    }

    This compiles without error - you can create a new project, create a new C# script, then add this to the end of the script and it will compile. However when you run it will tell you there is a compile error - afterwards I realized it was actually showing me where the error is but it's unclear why this doesn't get flagged from MonoDevelop when I compile. I had missed the error that appears at the bottom status bar when I run the project which then links me to the problem.

    So I am curious if there is a reason MonoDevelop does not flag this as an error immediately? I understand that in C# parameterless structs should not be used. They were in my project as I was porting in from another language.
     
    Last edited: Mar 29, 2016
    astarrysky likes this.
  30. BradOZman

    BradOZman

    Joined:
    Mar 10, 2016
    Posts:
    4
    I have tried all of these things.

    Im just trying to use the sample scenes downloaded from unity and I get this problem. If I click on the script in the inspector it show it highlighted in my assets folder.. Definitely there. Not my own scripts either freshly downloaded from vuforia site. Class names match the file names. Tried running as administrator tried all of the suggestions above. Please help me. I need this for an assignment lol. Cant get any of the vuforia scripts to recognize they are there in the inspector.


    OK got it... created a new project again this time in the my documents folder provided by windows.. copied all the packages there.. re-imported and did it all again.. For some reason it only worked from the my documents folder provided in windows... Doesn't work from my other HD where I keep all my files usually.
     
    Last edited: Apr 21, 2016
  31. SSScripting

    SSScripting

    Joined:
    Mar 30, 2016
    Posts:
    1
    Hi you must verify the name of class.
    you should have the same name for the script and class
     
  32. swap96

    swap96

    Joined:
    Aug 12, 2015
    Posts:
    1
    I was making a project on Unity 5.3.1 and this problem was not there but then for some reasons I had to switch over to Unity 5.2.3 and then this problem has started. The first time the project worked correctly and all scripts loaded successfully. But once I closed Unity and started it again then some of the scripts in camera and Gui Elements are not able to load. Is it because of going back to the previous version?
     
  33. mattparkins

    mattparkins

    Joined:
    Apr 1, 2014
    Posts:
    30
    For me it was a case mismatch between classname and filename - case has to match. Funny thing is that I can't remember changing either the classname or filename and it worked previously. I suspect Unity has updated something that means that this issue now comes up.
     
    paperpancake likes this.
  34. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    Another frustrating edge case, again with preprocessor #if:

    Code (csharp):
    1. // FAILS
    2. #if UNITY_5_4_OR_NEWER
    3. if(someVar) {
    4. #else
    5. if(someOtherVar) {
    6. #endif
    7.     // Some code...
    8. } else {
    9.     // Some other code...
    10. }
    Code (csharp):
    1. // Succeeds
    2. #if UNITY_5_4_OR_NEWER
    3. if(someVar) {
    4.     // some code
    5. }
    6. #else
    7. if(someOtherVar) {
    8.     // some code
    9. }
    10. #endif
    11. } else {
    12.     // Some other code...
    13. }
     
  35. MayorDump

    MayorDump

    Joined:
    Sep 30, 2016
    Posts:
    1
    I just had the same problem. Turns out all script names have to start with a capital letter. oops
     
  36. Ultimate360

    Ultimate360

    Joined:
    Oct 28, 2016
    Posts:
    24
    Hi, I need help; I am new to Unity, I followed the Unity's space shooter tutorial. My scripts work before, now it's not working. I think I got this problem after some inconsistent line endings error pop up occurred in Mono-develop.

    Actually, I don't know what's is line endings; the pop up error have drop down menu like:
    Windows (CR LF) <<< I selected this, I have no idea XD
    Macintosh (CR)
    Unix (LF)
    ...

    Sometimes I confirm it with "Windows (CR LF)", sometimes I just close/cancel it. It seem I got no problem. I don't know what cause of this problem, I have no error in the code. Now I tried to removed my Component (script) from my game objects, now I can't put it back (see the images). Maybe also the file modification detected pop up window may the cause (see the images)? Please tell me what have I done wrong?

    Here's my RandomRotator (script) anyway: (Nothing is wrong, right? All my scripts can not be loaded now)

    ------------
    using UnityEngine;
    using System.Collections;

    public class RandomRotator : MonoBehaviour
    {
    public float tumble;

    private Rigidbody rb;

    void Start()
    {
    rb = GetComponent<Rigidbody>();
    rb.angularVelocity = Random.insideUnitSphere * tumble;
    }
    }
     

    Attached Files:

    • U_01.png
      U_01.png
      File size:
      8.2 KB
      Views:
      1,109
    • U_03.png
      U_03.png
      File size:
      45.5 KB
      Views:
      2,809
    • U_04.png
      U_04.png
      File size:
      23 KB
      Views:
      1,336
    Last edited: Oct 30, 2016
  37. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,886
    It's very unlikely inconsistent line endings would cause it not to compile. I've never had that happen in all the years I've been using Unity on both Windows and OSX. Check the Unity console for an error message. Make sure error view is visible -- the Red (!) in the upper right corner of the console must be selected/highlighted. The error isn't necessarily in your RandomRotator script. The console will tell you which script has the error.
     
  38. Ultimate360

    Ultimate360

    Joined:
    Oct 28, 2016
    Posts:
    24
    Oh, thank you guavaman, now my scripts working again; it's just my GameController script have defects as I actually don't follow the tutorial as I do some experiments. I just delete my GameController script.

    (Oh nvm, you'll see all of your component scripts with "The associated script can not be loaded." error message when you close the Unity and reopen it again).

    Anyway guavaman, thank you so much... you save my day! :D
     
    Last edited: Oct 31, 2016
  39. yoyo696

    yoyo696

    Joined:
    Aug 11, 2015
    Posts:
    14
    me 2
     
  40. waterkulerbrush

    waterkulerbrush

    Joined:
    Oct 30, 2016
    Posts:
    8
    That Sucks! I just started using Unity this week, Bought a udemy course for 20 bucks. Everythign is going great then all of a sudden, a trigger that was working 20 minutes prior no longer worked correctly. Spent the last 2 hours googling ways to debug and print to console only to realize what I thought in the first place, Unity Error.

    Copied the scripts to my desktop, build and ran the game, closed it. Dragged the scripts back into unity, reattached them to the objects, boom, back in business. Pretty weird but i can deal with that goofy fix.
     
  41. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    691
    This happened to me today but there is NO way I can go back and re-attach everything. My project is huge. Is there no known fix for this?
     
  42. massivebacon

    massivebacon

    Joined:
    Apr 24, 2014
    Posts:
    15
    I'm running into errors with this directly related to preprocessor directives and exporting packages. I've got something like:

    Code (csharp):
    1.  
    2. namespace MyNameSpace {
    3. #if CLASS_EXISTS
    4. public class something {}
    5. #endif
    6. }
    7.  
    Where functionality is spotty at best. The code works in the main project, but if I try to export out those affected scripts through a package, the script breaks and is unable to be added to any components, even if the define is set. Calling stuff like AssetDatabase.Refresh() doesn't help this either. Would be glad to hear of any more info re directives and defining out classes.[/code]
     
  43. allenwithno3

    allenwithno3

    Joined:
    Dec 24, 2016
    Posts:
    2
    for me, the class name not matching script name, Rotator vs Rotater.. HAHA
     
  44. michalisc

    michalisc

    Joined:
    Jan 15, 2016
    Posts:
    1
    Hello the same problem happens to me,i import the Googe VR SDK and i get this error on evert script. "the associated script cannot be loaded"
    any solutions?
     
  45. Pnvanol

    Pnvanol

    Joined:
    Jan 11, 2016
    Posts:
    28
    same problem here
     
  46. HasanMougharbel

    HasanMougharbel

    Joined:
    Feb 4, 2017
    Posts:
    1
    You should make all the public class names and their relative script file names similar with both being in capital letters. Eventually, all scripts would run smoothly and excellently
     
  47. mino17

    mino17

    Joined:
    Jun 3, 2017
    Posts:
    1
    i don't have that problem when using visual studio
     
    Qbit86 likes this.
  48. blagy

    blagy

    Joined:
    Nov 22, 2015
    Posts:
    1
    i was stuck on this error for a day. solution for me was: deleted all unnecessary directives ("using") from all .cs
    i hope it helps u
     
  49. kmrothwell

    kmrothwell

    Joined:
    Sep 22, 2016
    Posts:
    1
    I had a particularly nasty case of this where I had unwittingly named a new class the same as another class in a namespace and then changed the file name. The files referencing the class in the namespace were now referencing the new class, the new class didn't have any public properties or methods so it seemed like it just wasn't picking them up. I couldn't search for the class in the file explorer because I had named it something different. Next time I'll just kick myself in the nuts...
     
  50. Rogue12

    Rogue12

    Joined:
    May 8, 2015
    Posts:
    1
    [SOLVED]
    I could fix it in one easy way!

    In my case:
    When i get the error in all scripts, i noticed that the last thing i write in c# was 2 IEnumerators.
    When i worked with 2 IEnumerators, this happens.. hmm..
    Try to remove them if you have (IEnumerators), and this can be fix.

    Sometimes IEnumerators dont work so well.. but that was in my case!
    At least i tried, but worked for me! :D