Search Unity

General problem with scripts: The associated script cannot be loaded

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

Thread Status:
Not open for further replies.
  1. areTeam

    areTeam

    Joined:
    May 11, 2017
    Posts:
    1
  2. Stoyer

    Stoyer

    Joined:
    Aug 14, 2017
    Posts:
    1
    Had the same problem as this. Was rebuilding a new streamlined database for an existing project. All the scripts were perfectly functioning scripts from the heavy database I was rebuilding. They worked fine before, and now they don't. I abandoned this new database I had begun to build that included the word "rebuild" in its name and started a new one using the word "reassemble" instead and the problem was gone. I will never include the word "build" in any project name, sub-folder, etc again (just to be on the safe side).
     
  3. Mazer83

    Mazer83

    Joined:
    Mar 14, 2016
    Posts:
    19
    The MessageBase class seems to be the source of my problems. I have a class that derives from it. I delete the ": MessageBase", and the problem goes away. I put it back, and the problem is still gone. I've had to do this more than once.
     
  4. Quinnd2006

    Quinnd2006

    Joined:
    Aug 13, 2017
    Posts:
    1
    Just started and I was using this tutorial


    And I saved and closed for the night came back and this happened.

    I deleted the scripts ( I had a backup) put them back in that was no help at all.
     
  5. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Hi guys,

    This happened to me suddenly. I have almost 2000 scripts. I filtered only scripts in the project view and right click to reimport them. The reimporting lasted short and it fixed the problem.
     
  6. Sabry_Hosny

    Sabry_Hosny

    Joined:
    Jul 28, 2016
    Posts:
    1
    Oh yaaa ..Hi
    the solution that worked for me is to change the windows local to English : go to Control Panel -> Region -> Administrative tab and change it to English (USA).
    I hope this works for you :)

    This solution was from OKBA28MCA
     
  7. Shin_Toasty

    Shin_Toasty

    Joined:
    Jun 15, 2017
    Posts:
    48
    In case anyone doesn't know: every script can fail to load because of ONE error in ONE script; it happened to me today. Using Unity 2017.2.0f3 64-bit BTW.

    Don't panic and look for the error. The console should tell you what it is. Fixing my one bad error restored everything.
     
  8. Marc_Bushido

    Marc_Bushido

    Joined:
    Aug 3, 2017
    Posts:
    1
    Hi has anyone found a fix for this? Im having this problem trying to upgrade to 2017. Brand new SSD, clean install of win 10, new install of 2017.2, new project, empty scene. Enters playmode fine. I then install Steam VR from the asset store and get this error. Same thing with Oculus integration from the store. The associated script could not be loaded etc.

    ANY help on this would be greatly appreciated!
     
    Qbit86 likes this.
  9. himerlandest

    himerlandest

    Joined:
    Nov 30, 2017
    Posts:
    2
    public class Spawner : MonoBehaviour {

    do not change this line code even a word, then my problem is solved
     
  10. darknubis365

    darknubis365

    Joined:
    Nov 12, 2017
    Posts:
    12
    Having this problem right now also
     
  11. Space_O

    Space_O

    Joined:
    Dec 3, 2017
    Posts:
    1
    [SOLVED]
    In my case:

    I started the new project in Unity and load de Vuforia Package (Unity Extension). And display the errors "The associated script can not be loaded".

    My solution: Reinstall Unity. Create a new project and NOT LOAD or DONT ADD de Unity Extension downloaded from Vuforia website. The latest versions of Unity have that integrated (2017). If you load the Unity Package you may have redundances (that was my case), and does not work.
     
  12. yewchunyen

    yewchunyen

    Joined:
    Oct 3, 2017
    Posts:
    8
    Hi All,

    Is that the latest version of Unity not able to apply with Vuforia? Why i got the error after reinstall Unity to latest version.

    Please help TT
     
  13. yewchunyen

    yewchunyen

    Joined:
    Oct 3, 2017
    Posts:
    8
    Hi bro, how should i check the classname and filename?
     
  14. yewchunyen

    yewchunyen

    Joined:
    Oct 3, 2017
    Posts:
    8
    Bro, what you meant.
     
  15. vanchanismo

    vanchanismo

    Joined:
    Feb 24, 2018
    Posts:
    1
    Thanks it solved the problem
     
  16. SharksInteractive

    SharksInteractive

    Joined:
    Jan 27, 2018
    Posts:
    17
    Meta files??? Are those just in the project folder somewhere?
     
  17. SharksInteractive

    SharksInteractive

    Joined:
    Jan 27, 2018
    Posts:
    17
    I do.
     
  18. angiemm

    angiemm

    Joined:
    May 26, 2017
    Posts:
    2
    in my case this was solved by troubleshooting read-only permissions on a folder in which I'd put some unity projects and where it was trying to store it's dll temp files. Grrrr! I didn't set up those permissions and at first couldn't seem to enable write-access. But then.... re-worked malware software settings and boom. Another wasted evening.
     
  19. TGMstudios

    TGMstudios

    Joined:
    Apr 30, 2018
    Posts:
    1
    Its dumb, fixing all compiler errors fixed every script
     
  20. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    I ran into this problem, and I just solved it, so I'm contributing to the thread.

    If you have this problem and none of the solutions in the thread work, your situation may just be a combination of them.

    The very short answer to my problem was that ScriptableObjects also need their own file named identically, just like MonoBehaviours.

    But I need to go into more detail because that problem hadn't shown up until I made a specific change regarding namespaces.

    Until recently, I have been using the default/global namespace for ALL of my game scripts.

    When I added a game namespace to all of my scripts, this one ScriptableObject file caused the "associated script cannot be loaded" error.
    But why would this happen now? Just because a namespace change? The code hadn't been changed for 6 months, and it was working fine!

    Here was the general format of my file:

    MyScriptableObject.cs
    Code (CSharp):
    1.  
    2. public enum MyEnum
    3. {
    4.     ...
    5. }
    6.  
    7. public class HelperClass1
    8. {
    9.     ...
    10. }
    11.  
    12. public class HelperClass2
    13. {
    14.     ...
    15. }
    16.  
    17. public class MyScriptableObject : ScriptableObject
    18. {
    19.     ...
    20. }
    This worked for several months until I changed this to:


    MyScriptableObject.cs
    Code (CSharp):
    1.  
    2. namespace MyGame
    3. {
    4.     public enum MyEnum
    5.     {
    6.         ...
    7.     }
    8.  
    9.     public class HelperClass1
    10.     {
    11.         ...
    12.     }
    13.  
    14.     public class HelperClass2
    15.     {
    16.         ...
    17.     }
    18.  
    19.     public class MyScriptableObject : ScriptableObject
    20.     {
    21.         ...
    22.     }
    23. }
    This resulted in the "associated script cannot be loaded" error. How could this be? Clearly, the filename matches the ScriptableObject name...

    So I did the experiment of breaking up all the classes into their individual files:

    MyEnum.cs
    Code (CSharp):
    1. namespace MyGame
    2. {
    3.     public enum MyEnum
    4.     {
    5.         ...
    6.     }
    7. }
    HelperClass1.cs
    Code (CSharp):
    1. namespace MyGame
    2. {
    3.     public class HelperClass1
    4.     {
    5.         ...
    6.     }
    7. }
    HelperClass2.cs
    Code (CSharp):
    1. namespace MyGame
    2. {
    3.     public class HelperClass2
    4.     {
    5.         ...
    6.     }
    7. }
    MyScriptableObject.cs
    Code (CSharp):
    1. namespace MyGame
    2. {
    3.     public class MyScriptableObject : ScriptableObject
    4.     {
    5.         ...
    6.     }
    7. }
    And then the error went away. So, you can see, I would never have seen this issue come up had I not added the namespace to my game scripts. And all of the responses to this thread mentioned MonoBehavours, but I don't think there was a mention of ScriptableObjects. And even then, I technically had the ScriptableObject name identical to the name of the containing file, and I still got the error. Something about the other classes confused Unity about the existence of the ScriptableObject.

    Now, you'd probably criticize me for containing a bunch of other classes and enums other than the ScriptableObject in the file. But when you've been developing a game for over 2 years, you tend to get a little sloppy. Regardless, this isn't all that unreasonable if the helper classes were tightly related to the ScriptableObject.

    Hope this helps somebody out.
     
  21. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I just had this happen. No compile errors. I tried reimporting, duplicating scripts and all sorts.

    I switched to .NET 3.5 and it went away, switched back to .NET 4.x and it did not return :/. Like aer0ace in the post above i often have enums and helper classes defined in the same file as mono behaviours. Maybe that confused it somehow? Why re-importing doesn't fix it when switch .Net version did i'm not sure. But now i'm worried there are other scripts that aren't properly linked elsewhere in the project.
     
  22. viktorasbrink

    viktorasbrink

    Joined:
    Sep 25, 2018
    Posts:
    1
    I had this issue when I wanted to introduce a new variable in a class, and wanted to take value from my game manager object. The issue was that I had a compile error saying that the variable didn't exist in the game manager, and when adding it, it caused this issue. I fixed it by copy pasting the exact same thing but adding it to the game manager before I looked it up in the other class. Really strange, something that should be looked at.
     
  23. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    ...Said guy from January 2014. Dear friend, writing to you from November 2018. This shame is still here. No diagnostics, no clear instructions. Just yellow “The associated script can not be loaded” everywhere.
     
    blairhoughton likes this.
  24. amdbuster

    amdbuster

    Joined:
    Nov 6, 2018
    Posts:
    8
    I have the same problem as the Threadstarter(The associated script cannot be loaded, please fix any compile errors and assign a valid script).
    I make C# Tuts since Weeks(Each Tut has a single Script), the last Yesterday, and all woks fine. But Today all Scripts have this error.

    Reimport doenst work.
    Why and where ist the problem?
     
  25. wechat_os_Qy03iycVZ_zXGI1qcDxyV0CUg

    wechat_os_Qy03iycVZ_zXGI1qcDxyV0CUg

    Joined:
    Aug 23, 2018
    Posts:
    1
    yes! This works for me!
     
  26. M_R_M

    M_R_M

    Joined:
    Jan 31, 2019
    Posts:
    26
    These kinds of bugs are growing old. All of the scripts in my entire project had been essentially removed and replaced with the aforementioned errors, and each one simply read "(script)" in the editor instead of the actual script name.

    I didn't rename any script, do anything to any folders, or otherwise change anything that should have led to this issue. There was no anti-malware digging around, every file name matched their respective class names, everything was working fine one second, and then in the middle of making a very simple change to a method, it did this. I didn't even save the changes to the script, the previous working version was still the active, last compiled script, Unity just froze briefly while I was in the middle of a line, and then decided I didn't need scripts for anything and removed them all and refused to let me re add them in any way.

    What fixed this for me was deleting the script I was working on, and then when Unity gave the error that another script couldn't find it, I simply commented out the references to it and then saved that script, and then all of my scripts came back to their game objects when I solved that (new and unrelated) error. Readding the same script I deleted and then uncommenting out the references in the other script again gave me no issues, so I know for a fact it is not the content of the scripts since they have not been changed since the issue began. Even deleting all of the scripts and reimporting (in numerous ways) didn't work, nor did deleting the metadata files, restarting, or various combinations of these. I essentially created an error so I could solve it, and somehow this fixed the issue. It doesn't make any sense.

    I really could've used these last 3.5 hours to work on my project instead of navigating bugs that shouldn't exist. Now I have to go to bed and wait another 18+ hours before I can even try to start making up lost ground from tonight. Very frustrating.
     
    Qbit86 likes this.
  27. Bertsn

    Bertsn

    Joined:
    Oct 26, 2017
    Posts:
    3
    I had the same error with scriptable objects. BUT the scriptable objects were working every now and then. When i created them they worked properly but when reloading the project they would sometimes crash.

    The issue was that the classname was different from the filename due to a typo. I only saw it after copy pasting the file name onto the classname.
     
  28. SharksInteractive

    SharksInteractive

    Joined:
    Jan 27, 2018
    Posts:
    17
    I have come to the conclusion it is happening because of an error in one of the scripts that it is not showing. This one script will throw off everything else!
     
  29. rnnicoletti

    rnnicoletti

    Joined:
    Sep 27, 2017
    Posts:
    4
    I ran into an absolutely enraging problem with this stuff over the past couple of days.

    I got this error when I added an explicit namespace to a source file that previously didn't have one. I stopped being able to add that component to game objects, and references I previously had to them broke. Very oddly, OTHER components that referenced this now-broken one still understood the type of that broken class in the editor. I couldn't for the life of me figure out what was wrong, but it was very clear that everything worked when I removed the namespace declaration, and it didn't when I re-added it.

    It seemed to me that this was some kind of corruption of some internal database, so I tried reimporting everything, and that didn't work. I tried closing everything, deleting all the meta files, and reopening the project, which also didn't work. I ended up working around this by making a new file with a different class name, moving all my code to the new class, and updating all the existing references to the new class name. Fortunately, right now I'm just poking at a prototype for something I wanted to play around with and not a project I've been working on for months, so that wasn't as horrifying as it could've been, but still... ouch.

    I ran into the problem today again and thought "Okay, there's no way that's a solution to an issue I might run into more than once", so I tried poking around at it a little more with a fresh brain. I noticed when I reimported today that in the Inspector window with the script selected, the "Import Settings" in the inspector had a message about there being no MonoBehaviour in the file or that the filename didn't match. Both of those were not true, though the class in question did inherit from another class that was a MonoBehaviour and wasn't itself a MonoBehaviour. While I was looking at that line, I noticed something: when you make a file by right clicking in the Project window and clicking "New C# Script", the generated code always looks like this:

    Code (CSharp):
    1. public class MyClass : MonoBehaviour
    My code looked like this:

    Code (CSharp):
    1. public class MyClass: ParentMonoBehaviour
    Can you see the difference? It was both unbelievable and enraging to me. When I had changed that inheritance/implementation clause, apparently I deleted everything after my classname and re-added the colon myself, without the space. When my class wasn't in an explicit namespace, that was fine. When it IS in an explicit namespace, this change in whitespace caused this error. Of course no error was thrown - this is NOT a compiler error! You can see code written the second way right at the top of Microsoft's own docs for the class keyword in C#:
    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/class

    I changed the source back and forth 3-4 times to confirm this was the problem, because the issue had caused me so much headaches for such an unbelievably subtle thing. My conclusion is there is some internal lexical process that is involved with connecting components to GameObjects in the editor that is separate from the build process that produces the underlying assemblies, and that lexer has a bug in the way it is tokenizing the class name in this very specific case.
     
    Last edited: Apr 5, 2019
  30. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Yes, the difference is in casing of MyClass vs. myClass (file name and class name). Well-known issue. Has nothing to do with spaces.
     
    JeffDUnity3D likes this.
  31. rnnicoletti

    rnnicoletti

    Joined:
    Sep 27, 2017
    Posts:
    4
    That was a typo in the forum post. My issue was with the spaces. I'll fix the post. What you're citing here wasn't the issue.

    Case sensitivity on type names is built into C# and has nothing to do with Unity. The only way for me to have had this as an issue in the Unity Editor and not in my code would've been for my filename to have a capital letter and all of my code references to have had it in lower case, not just that line.

    I understand that was an awful typo for me to have in my post, but I do hope you'd trust when I say that I name all my classes with upper-case letters by convention, so there's no way I wouldn't have run into this being a compile error before it caused me this headache.

    No worries if you don't, though; I'm already planning to build the toy project to demonstrate it and do a bug submission. I'll link it here when I get around to that.
     
    Last edited: Apr 5, 2019
  32. intellime

    intellime

    Joined:
    Mar 18, 2018
    Posts:
    14
    Hi,
    I had the same problem with Unity 2019.3.0a2 and Vuforia 8.1.11 and Ms Visual Studio Community 2017.
    I added a script with new class inherited from MonoBehaviour. I need to call it from Vuforia 'DefaultTrackableEventHandler' class but it couldn't found my class.
    My script file was located in Assets/Scripts and the DefaultTrackableEventHandler script file was located in Assets/Vuforia/Scripts.
    Non of the solutions worked but I moved my script file to the Assets/Vuforia/Scripts path. Then every thing works like a charm.
    It seems C# compiler separate Unity project structure into different C# projects and then build a VS Solution to gather them up. For me I can see 3 projects in my VS solution:
    1. Assembly-CSharp
    2. VuforiaEditorScripts
    3. VuforiaScripts

    So they can't see each other's classes unless you add one as a Reference to the other project.
     
  33. Michael_Berna

    Michael_Berna

    Joined:
    Jul 5, 2019
    Posts:
    39
    Still works well. This just saved me after I upgraded 20 2019.2.0.f1
     
  34. coolthings247

    coolthings247

    Joined:
    May 23, 2019
    Posts:
    5
    This worked for me. I had all project scripts fail. every single one. i had made a change to a script this morning so went back and changed that one line back and right clicked on the script to reimport. this recompiled and fixed the issue. so this comment here is correct.

    In case anyone doesn't know: every script can fail to load because of ONE error in ONE script; it happened to me today. Using Unity 2017.2.0f3 64-bit BTW.

    Don't panic and look for the error. The console should tell you what it is. Fixing my one bad error restored everything.
     
  35. DragonDmoney

    DragonDmoney

    Joined:
    Sep 22, 2019
    Posts:
    1
    I reimported everything, and deleted and pasted all my scripts in the asset folder. None of it worked
     
  36. flipper2017

    flipper2017

    Joined:
    Feb 25, 2017
    Posts:
    3
    similar problem: after loading the game all scripts couldn't be found
    I had this line:

    GameObject.Find("Image00").GetComponent<Image>().sprite = asprite;

    which was giving me
    "The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?) (CS0246)"

    I got that line working by adding "using UnityEngine.UI;" and all the scripts were back.
     
  37. zachgitt

    zachgitt

    Joined:
    Sep 23, 2019
    Posts:
    1
    For anybody using Visual Studio. My problem did not have to do with unity but rather visual studio was caching my old files. Restarting visual studio worked for me.
     
  38. csharpgam3dev

    csharpgam3dev

    Joined:
    Nov 7, 2019
    Posts:
    1
    when i delete .meta files and recompile everything. all textures turn solid purple. i tried several times, and it just wont fix.
     
  39. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    84
    I also had this issue and it was also linked to namespace and using statement inside the namespace declaration.
    So my solution is to either remove the namespace or to put the using statement outside of the namespace.
    There was no compiler error and trying to reimport or change project did not change anything.

    Code (CSharp):
    1. //Problem
    2. namespace N
    3. {
    4.       using T;
    5.       class C : MonoBehavior
    6.       //...
    7. }
    8.  
    9. //No problem
    10. using T;
    11. namespace N
    12. {
    13.       class C : MonoBehavior
    14. //...
    15. }
     
  40. rus89

    rus89

    Joined:
    Apr 22, 2015
    Posts:
    9
    That is working for me. Thank you very much. Appreciate
     
  41. premgps

    premgps

    Joined:
    Dec 16, 2019
    Posts:
    2
    Solved
    I had the same issue "associated script cannot be loaded"
    Go to build settings select android platform and click switch platform, unity will re compile all scripts, all the scripts will be loaded perfectly, this works for me, try this :)
     
  42. carldevelopsforcoffee

    carldevelopsforcoffee

    Joined:
    Sep 20, 2017
    Posts:
    19
    Got this error when I did this:

    Code (CSharp):
    1. unamespace Bonuses {
    2.   public class Minigame : MonoBehavior {
    3.   }
    4. }
    and

    Code (CSharp):
    1. namespace Bonuses {
    2.   public class SpaceGame : Minigame {
    3.    }
    4. }
    my fix on SpaceGame was this:

    Code (CSharp):
    1. using Bonuses;
    2.  
    3. public class SpaceGame : Minigame {
    4. }
     
  43. Halcomb

    Halcomb

    Joined:
    Jan 23, 2020
    Posts:
    3
    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
     
  44. SharksInteractive

    SharksInteractive

    Joined:
    Jan 27, 2018
    Posts:
    17
    With this bug unity never seems to be able to correctly determine which script the error originates from, primarily because when one script has an issue it causes all the scripts to stop working.
    I manually searched all my custom scripts starting at the ones I was working on before I had the issue and was able to find the source of it and fix it. Most likely an incorrectly typed name on a monobehaviour!
     
    Last edited: Feb 20, 2020
  45. Majesticlul

    Majesticlul

    Joined:
    Nov 3, 2019
    Posts:
    1
    spent so many hours trying to fix this thank you
     
  46. arm1975

    arm1975

    Joined:
    Mar 10, 2020
    Posts:
    1
    YOU HAVE TO MAKE YOUR SCRIPT NAMES, MATCH THE CLASS IN YOUR FILE! READ PEOPLE.
    for instance, if you name the script "ReadPeople" in Unity, then you must have this line in the file:

    public class ReadPeople : MonoBehaviour {
    }

    the script NAME has to match the CLASS NAME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
    MirrorO_O and WwAaSsUp like this.
  47. ElKevvin

    ElKevvin

    Joined:
    Dec 5, 2019
    Posts:
    1
    I Tried restarting my netbook and it works, always restart first (is easier)
     
  48. itisieric

    itisieric

    Joined:
    Jul 15, 2018
    Posts:
    4
    SOLVED
    on the Asset folder right click and select Reimport all
    if that did not work check your spelling of the file name and that the name in the script are the same
     
  49. Mostafa0Gad

    Mostafa0Gad

    Joined:
    Apr 27, 2020
    Posts:
    1
    Hi, I face this problem and after deep searching, the problem was the version of unity I use.So make sure that the scripts are from the same version of unity you use.
     
  50. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    I only started using started using scriptable Objects, and I am sporadically getting this error, it will sometimes break after a recompile sometimes get fixed, it happens so often that it makes it unusable I guess dont use it.
     
Thread Status:
Not open for further replies.