Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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. SuperCrow2

    SuperCrow2

    Joined:
    Mar 8, 2018
    Posts:
    584
    Did anyone else have this problem? Once I backed up my game onto C-Drive from my flash drives, only the score on the C-Drive no longer works on certain levels, but works on other levels. The score works on all levels on my flash drives. The weird thing is, every other script works perfectly fine on each level on C-Drive, except the score on certain levels.

    Anyone know what could be the problem? The score always works on my flash drives as long as I never back up the flash drives from C-Drive.

    I tried so many different things but never got it working again. Even made a new scene and still didnt work
     
  2. aguiarbrunoa

    aguiarbrunoa

    Joined:
    Jun 11, 2020
    Posts:
    1
    This also happened to me and I FOUND THE SOLUTION!!!!!
    The problem was that some scripts were obsolete and so I had to open them and a box appeared to say to "renew" them and then I did that and in the unity project there was a box that I think said to make all scripts compatible, or something like that, I clicked on that and after a while it's already solved.
    The only down side is that I had to open all the scripts to find what was obsolete.
    Another thing that may be causing this problem is the "scripts" of the shaders that can also be obsolete.
     
  3. Zasox

    Zasox

    Joined:
    Nov 28, 2013
    Posts:
    1
    just enable for red error and delete problem source
     
  4. Racine-Z

    Racine-Z

    Joined:
    Dec 10, 2015
    Posts:
    4
    THANK YOU, i disabled the red error tab and dont see that there is a erro but now it's all right
     
  5. bekthedev

    bekthedev

    Joined:
    Jul 12, 2020
    Posts:
    3
    Man You helped me
     
  6. cheesline

    cheesline

    Joined:
    Jul 22, 2020
    Posts:
    2
    i have the same problem I wanted to ad a script to move my figure in my 2D game but it happened nothing and the console said there is something wrong but i checked everything
     
  7. cheesline

    cheesline

    Joined:
    Jul 22, 2020
    Posts:
    2
    my script doesn’t work in my 2D Projekt (I want to control the figure): using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour{ public CharacterController2D controller; public float runSpeed = 40f; float horizentalMove = 0f; void Update(){ horizontalMove = Input.GetAXisRaw("Horizontal") * runSpeed; } void FixedUpdata(){ controller.Move(horizontalMove * Time.fixedDeltaTime, false, false); } }
     
  8. CGCowboy

    CGCowboy

    Joined:
    Mar 7, 2018
    Posts:
    17
    This is what worked for me...

    I had hundreds of scripts that ALL had this error so I thought it was project-wide.

    Turns out: During refactoring on one script, I removed a public variable which was fine for that script (compiled successfully). However, I forgot about another script (GameManager) that was referencing that variable.

    For whatever reason, this made entire project fubar. Every script in my project had this error. But, when I removed the line that was referencing the public variable no longer there, everything was in order again. Took me forever to triage this.
     
  9. Freakhealer

    Freakhealer

    Joined:
    Aug 27, 2020
    Posts:
    6
    ALL HAIL ROGUE12
     
  10. AtmosWork

    AtmosWork

    Joined:
    Nov 3, 2013
    Posts:
    15
    I had this problem today. I just edited some script, changed some variable, saved it. I opened Unity and saw that all shaders in the project were broken! In a panic, I reloaded the project, Unity started recompiling a scripts, and when everything was over, absolutely all scripts showed the "Missing" status.

    This method saved me: I deleted all metafiles from the Assets folder and restarted the project. Unity recompiling everything again and everything is working fine!

    Unity 2019.1.11f1
     
  11. DevinW

    DevinW

    Joined:
    Jun 19, 2014
    Posts:
    36
    I fixed it by removing a #region of comments that was outside of the namespace and class. No clue why this would have any effect.

    Code (CSharp):
    1. namespace Example
    2. {
    3.       public class ExampleCase : ScriptableObject { }
    4. }
    5.  
    6. #region
    7. //my comments
    8. #endregion
    Edit*
    On 2020.1.6f1, I did a full reimport of project files - deleted all solution files - removed scripts folder - removed all metafiles in scripts - renamed script - renamed class - none of that fixed it. Moving the regioned comments around is the only thing.
     
    Michael_Berna likes this.
  12. AlexDev_Official

    AlexDev_Official

    Joined:
    Apr 11, 2015
    Posts:
    2
  13. MendesGabrieljr

    MendesGabrieljr

    Joined:
    Feb 27, 2021
    Posts:
    1
    Try to see if the file name matches public or class YourFileName: MonoBehaviour {
     
  14. t00t_Man

    t00t_Man

    Joined:
    Mar 18, 2021
    Posts:
    1
    thank you so much ill try this later but I hope this works
     
  15. FronkisMan

    FronkisMan

    Joined:
    Mar 31, 2021
    Posts:
    1
    just tried that and lost my progress.
     
  16. pedroharres

    pedroharres

    Joined:
    Sep 14, 2018
    Posts:
    5
    none of the above solutions was working for me. My project uses Unity Collab (which btw I don't recommend) but in this case was helpful. I pushed my last version from project to the collab cloud and then reversed my project to previous version. all scripts were working again . then I updated It to the last version and it worked fine.
     
  17. Denis1122

    Denis1122

    Joined:
    Jan 6, 2020
    Posts:
    8
    The inclusion of Unsafe Code in the Player Settings helped me
     
  18. mart_hus

    mart_hus

    Joined:
    Mar 11, 2021
    Posts:
    1
    I am verry late to this, but i had the same probled , then i realized the name if my class was wrong ( i had renamed my file) so i fixed that deleted the .meta files and reopned the project, now it works
     
    Zape likes this.
  19. akayunus12

    akayunus12

    Joined:
    Jun 30, 2021
    Posts:
    1
    I've same problem. If you dlete ur last wrote script its turning back
     
  20. sudahi51

    sudahi51

    Joined:
    Aug 17, 2020
    Posts:
    7
    I'm working in Unity 2019.02.19 with a project connected to a Collab repo. I pushed some changes a few days ago and exited Unity. When I re-opened the next day after it ran the Collab updates and compilations it started giving the every script was unreachable error.

    So far I've failed to resolve the issue with the following solutions:
    1. Deleting and re-importing scripts from File Explorer
    2. Re-importing scripts from within Unity
    3. Deleting meta files and re-importing
    4. Reverting to previous Collab revision
    5. Checking if any class names and project names don't line up

    I'm the only person out of the 3 of us that has this issue and the other developer has pushed changes that I've seen working and my project cannot even compile anymore. Not sure what to try next other than try to re-import everything from a backup of the latest working version of the project?
     
  21. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    199
    "The associated script cannot be loaded."

    Sounds like this happens for a couple of reasons, judging from the varying solutions that worked for people.

    Wouldn't it be useful if Unity improved the warning message here? Given that this issue has been going on since 2013 and is really frustrating.

    At the bare minimum, it seems the warning should tell you the script it is referring to.

    Also, it says. "Fix any compile errors and assign a valid script." Given I don't have any compile errors in my project, there must be other reasons that a script is not "valid". It would be useful if the warning gave you more insight in that regard.

    Doing a Reimport All on my Assets directory did reveal some issues that may be the cause. Maybe the warning should make a suggestion to do that.
     
  22. sudahi51

    sudahi51

    Joined:
    Aug 17, 2020
    Posts:
    7
    FIXED: For me the issue was that when one of the other developers pushed changes to existing scripts to the Collab, when I tried to pull them down it did not update the code in the scripts that I already had existing versions of.

    1. Deleting and copying scripts in did NOT work - even after deleting metadata files.
    2. Reimporting did NOT work.
    3. Re-pulling from Collab did NOT Work.

    I only solved this by opening every script and manually copying the code from an updated version sent to me by the other dev into the old version that my project was trying to load. This cleared the compile error and allowed my scripts to run.

    The question now then is: Is there a reason we would need to manually copy all the code changes? We have a lot of changes being worked on by 3 people so this approach is 100% unsustainable to have to copy every updated file's code over manually after a pull.

    We're all using Unity Collab 1.2.16 and are running either Unity 2018 or 2019.
     
  23. david_d_david

    david_d_david

    Joined:
    May 26, 2021
    Posts:
    2
    Had the same issue where for all my attached scripts it said "the associated script cannot be loaded". I looked through my code and found that one line was referencing a script that no longer existed... nice. Now everything works fine. However, this seems like a common issue Unity should fix though.
     
  24. AdamStaszakVM

    AdamStaszakVM

    Joined:
    Sep 14, 2021
    Posts:
    1
    It's very stupid and just happened to me. Tried to find bug - no bugs, tried clearing caches, reloading, deleting project files, deleting meta etc.. Nothing helped. Wasted a lot of time, just to figure out... renaming script with visual studio and naming it like it was, solved problem...

    This is really stupid, it looks like Unity "unliked" name of script, saved it somehow - when I renamed script, reloaded it in unity it was working as should, then I renamed it as it was and unity somehow forgot, that it unliked it before...

    WHAT IS WRONG WITH THIS EDITOR AND IT'S CONSTANT STUPID PROBLEMS LIKE THAT??
     
  25. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,511
    It has something to do with Unity liking the names of the classes matching the names of the file that contains it. I don't know if it's particularly specified in documentation anywhere, but hey, you found a solution, which is great, and if you found it because of this thread, isn't it great that the thread existed in the first place?
     
  26. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,907
    https://docs.unity3d.com/Manual/CreatingAndUsingScripts.html
     
  27. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,968
    https://unity.com/learn
     
    Lurking-Ninja likes this.
Thread Status:
Not open for further replies.