Search Unity

Bug Scripts don't work

Discussion in 'Scripting' started by benjamindavidrichardhasluck, Dec 7, 2020.

  1. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    I change the name of a class in a script to something that isn't the name and now every script is apparently invalid.
     
  2. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    For MonoBehaviours, the script filename does need to match the class name.

    That wouldn't make "every script" invalid, it would just prevent you from attaching the misnamed script to an object. So there's most likely something else wrong.

    Copy and paste the actual error message. Paraphrased error messages are utterly useless in diagnosing a problem.
     
  3. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    This is what shows with the script I changed:
     

    Attached Files:

    • a.PNG
      a.PNG
      File size:
      25 KB
      Views:
      306
  4. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    And this with every other attached script of which I didn't change:
     

    Attached Files:

    • b.PNG
      b.PNG
      File size:
      8 KB
      Views:
      301
  5. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    You have compile errors. Check your console (open it by clicking on the bottom bar of the Unity window)
     
    Bunny83 likes this.
  6. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    How can I fix this?
     
  7. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    The things I've already said:
    We don't have enough information to help you yet.
     
  8. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    Ohhhhhh you mean ones like this:
     

    Attached Files:

    • c.PNG
      c.PNG
      File size:
      4.9 KB
      Views:
      297
  9. Ray_Sovranti

    Ray_Sovranti

    Joined:
    Oct 28, 2020
    Posts:
    172
    Yes, that's the one.

    Most of the time this error means you have two copies of a script file in your project somewhere. Look for other scripts containing a class of the same name.

    If you can rule this out, I have occasionally seen a Unity bug when renaming a script file where it thinks the old script file still exists and sees them as duplicates. If that's the problem, restarting Unity will probably fix it. If it doesn't, then deleting the Library folder probably will (MAKE A BACKUP of your project before deleting that)
     
  10. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    I just realised that for some reason all my scripts duplicated
     
  11. benjamindavidrichardhasluck

    benjamindavidrichardhasluck

    Joined:
    Apr 7, 2020
    Posts:
    24
    This was the problem - thanks!