Search Unity

No MonoBehaviour scripts in this file?? {Answered}

Discussion in 'Scripting' started by NintendoMaster00, Mar 28, 2015.

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

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    In unity 5 i tried making a script but when I do it shows what i included in the pic.
     

    Attached Files:

    paravarz and Mathusalemrex like this.
  2. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    bump i still have not figured this out
     
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What's the exact file name? If it is anything else then NewBehaviourScript.cs, it won't work. Upper and lower cases have to be identical as well.
     
    shawnlauzon likes this.
  4. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    that is the exact file name, it is the default file name when I make a C# Script
     
  5. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Are there any compile errors?
     
  6. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    Nope also i tried making another script and it is there when i first make it but if i click it again it is gone..


    edit: when i click on the new script this came up as another script :
    Code (CSharp):
    1. Microsoft Visual Studio Solution File, Format Version 11.00
    2. # Visual Studio 2008
    3.  
    4. Project("{16FBE60A-881B-252E-4171-415BB07D355C}") = "Game Name", "Assembly-CSharp.csproj", "{132D20DC-77BA-457C-3BBD-F4AA182776AC}"
    5. EndProject
    6. Global
    7.     GlobalSection(SolutionConfigurationPlatforms) = preSolution
    8.         Debug|Any CPU = Debug|Any CPU
    9.         Release|Any CPU = Release|Any CPU
    10.     EndGlobalSection
    11.     GlobalSection(ProjectConfigurationPlatforms) = postSolution
    12.         {132D20DC-77BA-457C-3BBD-F4AA182776AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    13.         {132D20DC-77BA-457C-3BBD-F4AA182776AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
    14.         {132D20DC-77BA-457C-3BBD-F4AA182776AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
    15.         {132D20DC-77BA-457C-3BBD-F4AA182776AC}.Release|Any CPU.Build.0 = Release|Any CPU
    16.     EndGlobalSection
    17.     GlobalSection(SolutionProperties) = preSolution
    18.         HideSolutionNode = FALSE
    19.     EndGlobalSection
    20.     GlobalSection(MonoDevelopProperties) = preSolution
    21.         StartupItem = Assembly-CSharp.csproj
    22.         Policies = $0
    23.         $0.TextStylePolicy = $1
    24.         $1.inheritsSet = null
    25.         $1.scope = text/x-csharp
    26.         $0.CSharpFormattingPolicy = $2
    27.         $2.inheritsSet = Mono
    28.         $2.inheritsScope = text/x-csharp
    29.         $2.scope = text/x-csharp
    30.         $0.TextStylePolicy = $3
    31.         $3.FileWidth = 120
    32.         $3.TabWidth = 4
    33.         $3.IndentWidth = 4
    34.         $3.EolMarker = Unix
    35.         $3.inheritsSet = Mono
    36.         $3.inheritsScope = text/plain
    37.         $3.scope = text/plain
    38.     EndGlobalSection
    39. EndGlobal
    40.  
     
    Last edited: Mar 30, 2015
  7. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If you create an empty project, can you create a new script in there without that issue? Is it possible to create the script and then directly add it to a game object?
     
  9. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    Yes it seems to only be on 1 project i might have changed some setting mistakenly.
     
  10. ExileGamesStudio

    ExileGamesStudio

    Joined:
    Mar 26, 2015
    Posts:
    19
    This happened to me when I first started using Unity last week. It turned out a script I was working on but deleted was still being picked up by unity. I went into my documents and deleted the script from there and the error went away. Im new to programming so I don't know much at all but that's what worked for me with so its worth a shot brother
     
    Kavi246 and Adro05 like this.
  11. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    I think that may be what i did as well when i deleted it, the error is now gone thanks for the help guys!
     
  12. Wrenhen

    Wrenhen

    Joined:
    May 2, 2015
    Posts:
    1
    When I deleted the script in my document it got rid of it in my game to.
     
  13. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    yes it will do that the folders are connected (eg. if you make a folder in your games folder it will appear in unity as well)
     
  14. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    I figured it out it was my McAfee real time scanning messing it up; I just deactivated it and the problem was fixed.
     
  15. jmasinteATI

    jmasinteATI

    Joined:
    Jul 14, 2015
    Posts:
    7
    I just had the same problem. My solution? Copy and file's content. Delete the file. Re-create the file and paste the content into the re-created file. The error went away.
     
  16. j0shb3lk1n

    j0shb3lk1n

    Joined:
    Oct 25, 2015
    Posts:
    1
    I know i'm late but i just got unity tonight and i cant fix the problem with any of the above solutions.
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Welcome to the forums!

    You most likely have a compilation error in your script. The easiest way to get help is by posting the script here. Don't forget to use code tags:
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  18. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    Welcome to Unity!

    Do you have any errors other that that it says there are no monobehaviour scripts with the file?
     
  19. tecbug

    tecbug

    Joined:
    Nov 19, 2015
    Posts:
    16
  20. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    has this happened with any of your other scripts or just this one?
     
  21. tecbug

    tecbug

    Joined:
    Nov 19, 2015
    Posts:
    16
    I had couple of scripts that worked correctly. But suddenly they all stopped working. From this moment even new scripts in this project doesn't work.
    If I make new project - scripts work there correctly, but when I copy scripts from first project error is back again.
     
  22. Hamburgert

    Hamburgert

    Joined:
    Feb 14, 2015
    Posts:
    6
    I just had the same error-message. Posting because different solution than described above.

    I had to extend every "base" class with MonoBehaviour. (using Javascript)

    The wrong way (in my case - also led to the error on scripts extending the Road class):
    class Road{ /* all road related code here*/}

    The "fixed" way (in my case - also fixed the error on scripts extending the Road class):
    class Road extends MonoBehaviour{/* all the same road related code here*/}
     
  23. AlmiraGonce

    AlmiraGonce

    Joined:
    Jan 30, 2016
    Posts:
    1
    I just experienced the same issue on one of my code but then when I open again Unity all other codes got affected. It says "All compiler error have to be fixed before you enter play mode." Is there anyone know how to fix this? It's my thesis and on Saturday is the presentation. Thank you so much in advance.
     
  24. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    Do you have McAfee? If you do turn off real time sharing and reopen your unity project this should fix it.
     
    Last edited: Feb 3, 2016
  25. WuWanjia

    WuWanjia

    Joined:
    Nov 18, 2015
    Posts:
    6
    How to fix it !?!?!?
     
  26. Larrson2014

    Larrson2014

    Joined:
    Jun 8, 2016
    Posts:
    2
    This is my first time using unity and none of the above worked for mr, this is my code:

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour (

    private Rigidbody2D rb2d:

    void start()
    (
    rb2d = GetComponent<Rigidbody2D> ():
    )

    void FixedUpdate ()
    (
    float moveHorizontal = input.GetAxis ("Horizontal"):
    float moveVertical =input.GetAxis ("vertical"):
    Vector2 movement = new vector2 (movementHorizontal, movementVertical):
    rg2d.AddForce (movement):
    )
    )



    This is my error

    No MonoBehaviour scripts in the file, or their names do not match the file name.


    Thank you so much in advance!
     
  27. ycode

    ycode

    Joined:
    May 1, 2016
    Posts:
    4
    Umm, why do you use colon at the end of a line of code?
    you need to use semicolon in C#.

    whatever IDE you use to code, your code should be able to be successfully compiled before run it on Unity.

    by the way, I had the same error on Unity 5.3.5f1 for another reason, and it made me puzzled for a little while... so I leave a note here. I hope it helps somebody.

    My finding is:

    "Do not make methods with optional parameters in interfaces."

    For example, if you add a C# script on Unity, naming it BeeBehaviour, and edit the code on VS as follows, then you will see the error message on Unity, "No MonoBehaviour scripts in this file", even though it can be built successfully in VS.

    public interface IBeeBehaviour
    {
    void DoSomething(int request = 0);
    }
    public class BeeBehaviour : MonoBehaviour, IBeeBehaviour
    {
    public void DoSomething(int request = 0)
    {
    throw new NotImplementedException();
    }
    }

    look at DoSomething method. It has an optional parameter. If you change it to "void DoSomething(int request);", the error will disappear.

    well, but if you really want to use optional parameter, there's a way. Move the interface definition to another file. then everything will be fine.

    It looks that there's some issue in Unity's c# code parser.
     
  28. aitchest-of-dees

    aitchest-of-dees

    Joined:
    Dec 28, 2013
    Posts:
    73
    For me, going to Assets->Refresh seemed to fix it.
     
  29. theblindprophet

    theblindprophet

    Joined:
    Aug 23, 2016
    Posts:
    1
    I had a "-" in my file name (touch-script) and that was breaking it for some reason. I assume in the line:

    `public class touch-script : MonoBehaviour {`

    so I changed the name to "touchScript".
     
  30. Zeeshan_

    Zeeshan_

    Joined:
    Nov 21, 2016
    Posts:
    1
    Hello.
    i am also new to unity and i am also having the same problem and i have tried all the above solutions except for del the old script. since i hav'nt created another so that should be ok.
    and i have compiled my errors as well but everything is seems to be ok.
     
  31. Flashpants

    Flashpants

    Joined:
    Nov 19, 2016
    Posts:
    1
    Having looked at many ineffective solutions to this I have just solved this issue myself:

    There was not an issue with the new script that I created at all (after all, it was a new "blank" script so there was never likely to be any compile or naming issues with it (which has been suggested by many people)). The issue was with another, entirely separate script - once I deleted this script and then clicked on "reimport all" (right click on assets folder to do this) then the error disappeared for all of the remaining scripts.

    You may wonder what the problem is in the script I deleted - unfortunately I do not know. I had imported the problem script as part of an asset pack from the asset store. The store had warned me that there may be compatibility issues with the asset pack before I imported it but because I only needed to steal a few textures and wasn't actually using any of the scripts I didn't think this would be a problem. As it happens, a single unused script within the asset pack ruined all of the other scripts until it was deleted.

    Hope this helps someone!
     
    Lillemann0, c4cqi and BrentDaMage like this.
  32. Orange-Pixell

    Orange-Pixell

    Joined:
    Jul 28, 2015
    Posts:
    1
    This happened to me after I renamed the script after I created and wrote the script. Deleting and recreating or refreshing or reimporting, etc nothing worked. Renaming again to name I gave to the script when I created it had solved.
     
  33. wahidelgendy

    wahidelgendy

    Joined:
    Apr 9, 2017
    Posts:
    1
    that happens if you change the script name after creating it. you can change the public class name to the new name in the script code or rename to the old name or create new script
     
  34. IbraheemTuffaha

    IbraheemTuffaha

    Joined:
    Apr 13, 2017
    Posts:
    3
    I'm having the same problem, weather I use a script from the built-in packages like Character for example, Or I just make a new empty project and add a new script with default code (file name and class name are the same):

    Also the console gives me an error with no text in it whenever there is a script in the assets!
    I tried:
    Using both MonoDeveloper and Visual Studio.
    Stop Windows Defender real time protection.
    Remove and reinstall Unity with deleting all files related to it.
    Making new project and adding a new script.
    None has worked for me, please let me know if you have a solution for it.
     
  35. UnwantedOrphanX

    UnwantedOrphanX

    Joined:
    Apr 18, 2017
    Posts:
    2
    hey guys im new to unity as well and im making my first endless runner and with the script im using it aslo says no mono..... what do i do? problem.png
     
  36. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,192
    Both the filename and the class name of the script need to match. You will need to rename one of them.
     
  37. UnwantedOrphanX

    UnwantedOrphanX

    Joined:
    Apr 18, 2017
    Posts:
    2
    fixed the script now just copy this....


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour {

    public float movespeed;
    public float jumpforce;

    private Rigidbody2D myRigidbody;

    // Use this for initialization
    void Start () {
    myRigidbody = GetComponent<Rigidbody2D > ();
    }

    // Update is called once per frame
    void Update () {
    myRigidbody.velocity = new Vector2 (movespeed,myRigidbody.velocity.y);

    if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) )
    {
    myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpforce);
    }
    }
    }
     
  38. tariqqubti

    tariqqubti

    Joined:
    Apr 15, 2017
    Posts:
    2
    Hello everyone,

    I'm getting the same "No MonoBehaviour scripts in this file, or their names do not match the file name"
    Environment is:
    - Windows 10 Pro 64-bit
    - Fresh Unity 5.6.0f3 Install
    - Fresh project
    - C# script has nothing in it (see attachment)

    Not sure if I'm missing something here, just started to use Unity.
    It seems that if I removed the C# script file and add a Javascript script file the error disappears, though I want to use C#, could it be a C# version thing?
    I had Visual Studio 2015 installed on the machine before installing Unity, and when I installed Unity it installed a version of Visual Studio 2017 I guess Community edition, could that be the conflict, though I set MonoDevelop as the default editor... any hint would be great.

    Thanks,

    unity_error.jpg
     
  39. tariqqubti

    tariqqubti

    Joined:
    Apr 15, 2017
    Posts:
    2
    Hello there,

    I managed to find the solution from this thread https://forum.unity3d.com/threads/compiler-error-with-empty-description.465840/
    The solution was for me to change Windows locale to a non-Arabic one like "English (United States)"

    You can change it from:
    Control Panel >> Clock, Language, and Region >> Language >> Change date, time, or number formats >> Administrative (Tab) >> Change system locale... (Button) >> Pick English (United States)
    Windows will ask to restart

    Hope it helps...
     
  40. IbraheemTuffaha

    IbraheemTuffaha

    Joined:
    Apr 13, 2017
    Posts:
    3
    The Script file name is Player and the Script class name is PlayerController.
    The name of the file should match the name of the class.

     
  41. IbraheemTuffaha

    IbraheemTuffaha

    Joined:
    Apr 13, 2017
    Posts:
    3
    The problem might be from the System Locale, check the solution in the beginning of the first Answer:
    http://stackoverflow.com/questions/43403709/unity-built-in-packages-compiler-errors
     
  42. HudsonB

    HudsonB

    Joined:
    May 16, 2017
    Posts:
    1
    Same thing happened to me. I'm a beginner but I just copied the content of the script, deleted the Script file, re-created the file, and then pasted into the new script. Error message went away.
     
  43. Wilbrick

    Wilbrick

    Joined:
    May 22, 2017
    Posts:
    1
    Same problem...I'm a super beginning so I'm really kind of helpless...here's the code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace HumanAPI
    5. {
    6.     [AddComponentMenu("Human/Respawning Rigidbody",10)]
    7.     public class RespawningBody  : MonoBehaviour
    8.     {
    9.         public float despawnHeight=-50;
    10.         public float respawnHeight=5;
    11.  
    12.     }
    13. }
    14.  
    help pls
     
  44. michaelb212

    michaelb212

    Joined:
    Jul 21, 2014
    Posts:
    8
    I Had this problem after i renamed the script file,
    The problem turned out to be that the file name and class name where not the same (file name was playerController.cs while class name was 'PlayerController'
    Different casing for the first letter.
     
    TaleOf4Gamers likes this.
  45. caoxinan2017

    caoxinan2017

    Joined:
    Nov 1, 2017
    Posts:
    1
    I am a new one:)
    I encountered the same problem at the beginning as below,
    when I created a new script not have any change even the name, it has the problem "No MonoBehaviour scripts in this file, or their names do not match the file name"
    after I change the script name to PlayerControler and at the same time change the class name to the same.
    the problem disappeared.
     
  46. Juice118

    Juice118

    Joined:
    Dec 12, 2011
    Posts:
    11
    I have this problem, but found a workaround that whilst annoying does work.
    If I create a script in Unity with Visual Studio open I get this error 100% of the time in one of my projects..
    However if I close Visual Studio, create the script in Unity and then open it by double clicking it within Unity it works.

    Its like the using statement that monobehaviour requires is not being recognised, despite the correct using statements (using UnityEngine;)
    You will notice in any script with this error hovering your mouse over either using UnityEngine; or Monobehaviour gives you no information, whereas ones that work will.
     
  47. Gaming_geko

    Gaming_geko

    Joined:
    Oct 17, 2017
    Posts:
    4
    I just fixed any compile errors I had in other scripts and it fixed it.
     
  48. christianbegg2

    christianbegg2

    Joined:
    Jul 27, 2018
    Posts:
    1
    I am having the same error. I got it to work once and the script didn't work. I got out. Got back In and it started up again Capture.PNG
     
  49. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What is the filename of the MOVEME class?
     
  50. Sorgoroth

    Sorgoroth

    Joined:
    Aug 30, 2018
    Posts:
    1
    I had this problem not so long ago. My fix was simply fixing all the ,,other'' errors or just commenting them out. Sounds bizarre. However it fixed this.
     
Thread Status:
Not open for further replies.