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

Monobehaviour not detected in file

Discussion in 'Scripting' started by shebli7, Apr 3, 2017.

  1. shebli7

    shebli7

    Joined:
    Apr 2, 2017
    Posts:
    4
    Hi,
    I am just starting to learn Unity (just yesterday) ...well "trying" to start learning until i got this annoying error.

    I just create a C# script in a new project and right from the beginning i get hit by a "all compiler errors need to be fixed ...bla bla bla"

    even though the project is freshly new, no other scripts are there only this new one. the error keeps popping. if i delete the script everything goes fine. i try creating a new one and the problem appears again. i searched for two straight days for a fix with no results. so far i tried doing this :

    1) made sure the name of the class and the name of the file are exactly same (lower upper case included). keep in mind this happens even if i just click create script with no change.
    2) did the refresh reimport all from the assets menu.
    3) delete all projects and reinstall unity again.
    4) disable antivirus software
    5) restart windows over and over
    6) restart unity and try deleting all projects and documents and create fresh ones.
    7) tried both monodev and visual studio both show no errors in the script.

    I am running the latest version of unity (5.6) on windows 10 with latest updates.

    Would really appreciate the help on this one. its driving me crazy but i am really into learning this thing.
     
  2. shebli7

    shebli7

    Joined:
    Apr 2, 2017
    Posts:
    4
    I think I should add that When i check the console for errors i just find one single red exclamation mark with no text or details. I try to click on it and nothing happens. Try to clear console and nothing happens the red mark is still there
     
  3. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
  4. shebli7

    shebli7

    Joined:
    Apr 2, 2017
    Posts:
    4
    Thanks for the reply!
    Though like i said its the default template that is created when you create a new script file. Anyway below is the script (note that i made sure the class name is exactly as the file name)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.       void Start() {
    7.       }
    8.  
    9.       void Update() {
    10.       }
    11.  
    12.  
    13. }
    14.  
    15.  
    16.  
     
  5. shebli7

    shebli7

    Joined:
    Apr 2, 2017
    Posts:
    4
    Any hep :(
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    If the autogenerated script doesn't work, that's a bug.

    It might be that Unity for some reason don't get to read your script. Try starting Unity as administrator.

    It might be that Unity broke something in 5.6, so you could try going to the download archive and download 5.5.
     
  7. programmerjason

    programmerjason

    Joined:
    Mar 4, 2017
    Posts:
    1
    @shebli7 recently this started happening to me. I was thinking it was a bug with Unity 2018.26 or some how a bug between an interaction with VS2017 and Unity 2018. I reimported my program and the error went away. However, whenever i added a new script the error would come back.Then I noticed an extra ";" in one of my programs and removed it. The error went away permenately. Hope this helps anyone else who finds this.
     
  8. Gong2

    Gong2

    Joined:
    Apr 26, 2016
    Posts:
    3
    Had the same problem.

    Firstly, I deleted the meta files of those scripts and reopened Unity, then I changed the name of the class in VS then in Unity and it worked.

    Using Unity 2018.3.12f1 with Visual Studio 2017 Community.

    Hope this help!
     
    Noah_Dry likes this.
  9. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    171
    I had the same problem using 2019.3 . So I copied contents of the script to Notepad. Deleted the script and created a new one. When I pasted the script back from Notepad the problem happened again. So I then cleared the script and pasted back from Notepad one line at a time and it worked!

    I tried this several times and am convinced there is some hidden formatting which was corrupted.

    So if you have this I would first try copying everything out to clear your script, then paste back line by line checking each time.
     
  10. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,125
    I had the same problem in Unity 2020.1.14f and my solution, bu surprise, was to create a new script. When I did that the problem disappeared totally.
     
  11. Shakaron

    Shakaron

    Joined:
    Feb 15, 2021
    Posts:
    1
    After updating from Unity 2020.3.7f1 Unity 2020.3.6f1 I had the same problem. None of my scripts using Monobehaviour found that class.

    Microsoft Visual Studio Community 2019, Version 16.9.4

    I have 20+ scripts in my project.

    I just added a new (empty) script file via the Unity Editor and that fixed the problem. Now the code builds fine. I could remove the empty C# script file and everything still was working.

    I think this must be a bug. A missing reference or confused metadata file.
     
  12. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,904
    That's not updating, that's downgrading. And Unity doesn't support any form of it. You always need to revert your project in your version control system or load back a backup. And as the update alert dialog says always backup your project before you update it to a new version. It is not a joke.
     
  13. morbden-dev

    morbden-dev

    Joined:
    Apr 17, 2021
    Posts:
    1
    Never use space in scripts name!

    'My Script.cs' Not work.
    'MyScript.cs'. Work Normaly
     
  14. aquilis007

    aquilis007

    Joined:
    Aug 11, 2016
    Posts:
    6
    Exatamente, obrigado
     
  15. ivanbravo261

    ivanbravo261

    Joined:
    Jun 2, 2019
    Posts:
    1
    worked for me!
     
  16. aliozan7

    aliozan7

    Joined:
    Jul 18, 2021
    Posts:
    1
    Open Edit->Preferences->External Tools change the external script editor back and forth and then click "Regenerate Project Files"
    that was the thing that worked for me
     
    ameer-fares likes this.