Search Unity

Why when i open a new script in visual studio the MonoBehaviour is not in light blue ?

Discussion in 'Scripting' started by Chocolade, Nov 2, 2017.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    933
    I marked with red circle what i mean it's not in light blue:



    And marked in blue circle this example to show how it is suppose ot be:




    In the editor in the Project > Assets > My Scripts > Ladder > mouse right click Create > C# Script give it the name Raise then double click but i can't use it since the MonoBehaviour is not active not in light blue.
    Other scripts have it fine.

    Not sure what is wrong. I tried to give it other names like RaiseLadder or Raise Ladder but each time i create the script it's not working.
     
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Its a bug with VS and Unity. Sometimes the VS intellisense just breaks. Usually deleting the Library and the .csproj/.sln files fixes the issue. These folders get recreated by Unity upon reopening the project.
     
    Last edited: Sep 3, 2021
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Sometimes the .cs file will be opened as a single file that has not been registered properly in the project file yet, hence your assembly references and other source files are not accessible from the newly created script.

    I can only speak about personal experience, but for me, this mostly (or even exclusively) happens when I use 'Enter' on a newly created script. Double click does usually work like a charm and triggers a solution-reload dialog as soon as VS gets focused again.

    Once you run into this problem, it is usually enough to close VS and re-open with Unity. If that doesn't fix it right away, you still got the option that @TaleOf4Gamers has mentioned.
     
    Joan8a, billykatz, jjbish and 5 others like this.
  4. Neutrinora

    Neutrinora

    Joined:
    Jun 5, 2016
    Posts:
    3
    It caused by Renaming Project Folder after project creation.
    Simple Solution: Rename your project file to original.
    Boring Solution: After you create your script, go to VS and find your newly created script in the solution explorer panel. Right click and choose "Exclude from Project". Then right click your Assets folder on solution explorer, select Add context, and then select "Existing Item" option. Then choose and add your newly created script file from this window. That fixes the problem. But still you have to do that for every single script.
     
    Kodesh and Richardm1985 like this.
  5. Vivec73

    Vivec73

    Joined:
    Oct 29, 2016
    Posts:
    3
    Hello. I think this post is relatively old. Please excuse me for my english. I seem to have found the solution to this problem.
    Right click Assembly-CSharp in the solution explorer and click unload the project. Then redo the same manipulation but this time to reload the project. Alleluia it works again ;-)
     
  6. Deleted User

    Deleted User

    Guest

    I add this problem today; I just quit both Unity and VS and restarted them and the problem solved itself.

    I hope this will be fixed in future versions.
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I generally only hit weird issues like this when I create a new CS file and try to open it before Unity has finished recompiling from the change.
     
  8. Deleted User

    Deleted User

    Guest

    I'm afraid this is not the reason; I just created a script and opened it about 30 seconds after creating it and the problem is there. It doesn't take that long to Unity to compile a new empty script.

    Only fix: closing VS and restarting it.
     
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    I think generally VS with Unity has bad synchronization.
    I didn't hit issue as yours. But VS desyncing is not something uncommon for me.
    So there may be something else going on.

    Try in Unity Ctrl+R tor refresh, after script is created.
    Or create script from VS. And copy, or type MonoBehaviour manually.
     
  10. PizzaPie

    PizzaPie

    Joined:
    Oct 11, 2015
    Posts:
    107
    They ve fixed it, download latest Tools for Unity and Visual Studio 2017, there is a post in VS forums stating so. Anyway for me it does not happen anymore.
     
  11. Deleted User

    Deleted User

    Guest

    I'm already using VS 2017 and the latest tools for Unity and the latest 2018.2 Unity: it's not fixed.
     
  12. JonathanHaken

    JonathanHaken

    Joined:
    Nov 26, 2018
    Posts:
    1
    Here is a quicker workaround I fixed.

    Problem:
    Visual Studio 2017's intellisense doesn't recognize new MonoBehaviour scripts in generated from Unity.

    Workaround:
    Right-click the project in VS and unload the project (shortcut-L), right-click again and load it (shortcut-L again).

    All MonoBehaviour scripts created hereafter no longer require the workaround. Visual Studio magically recognizes newly created scripts! I don't understand why, but it works.
     
    AndorNextDoor likes this.
  13. knoxx014

    knoxx014

    Joined:
    Mar 5, 2019
    Posts:
    1
    It is i! A random Necromancer passing by, i actually fixed this problem in Unity and Visual Studio Link, the monobehaviour not being highlighted.

    I fixed it by Unity > Edit > Preferences > External Tools > External Script Editor > (Change it to) Visual Studio 2017 (Community)

    then restart both programs.
     
  14. Deleted User

    Deleted User

    Guest

    If I recall correctly, this was happening with Visual Studio already. The problem seems to have been fixed with the most recent versions of Unity; I haven't seen it happening in 2018 or 2019 yet.
     
  15. Muntaha_Islam

    Muntaha_Islam

    Joined:
    Apr 22, 2019
    Posts:
    1
    Thanks a bunch for the solution.
     
  16. jakediep92

    jakediep92

    Joined:
    Aug 4, 2019
    Posts:
    1
    Thanks for the solution.but i found before i saw you 3 minute later. T T
     
  17. Xrayer

    Xrayer

    Joined:
    Jun 28, 2018
    Posts:
    2
    THANKS FOR THAT, searched for hours, many thanks!
     
    JustJat likes this.
  18. GrayDwarf

    GrayDwarf

    Joined:
    May 6, 2015
    Posts:
    9
    If you don't have Visual Studio 2017 as an option, go to Start (Win10), type Visual Studio, right click on your preferred version (2017), select 'open file location', right click on the 'Visual Studio 2017' shortcut and select properties. Copy the full Target path without double quotes. Close out of these windows and get back into Unity.

    Unity > Edit > Preferences > External Tools > External Script Editor > Browse

    then paste your full path in without quotes and hit Open. You should now see the friendly name for "Visual Studio 2017". Close out of Preferences and double click your script file. Should open as expected now.

    Thanks to everyone that came before me.
     
    kevin_x_johnson and GreenSkull5 like this.
  19. Panimu

    Panimu

    Joined:
    Mar 11, 2020
    Posts:
    2
    This worked for me, didn't restart unity (VS was already closed).
    NB: Using VS 2019
     
    kevin_x_johnson and JustJat like this.
  20. CountVonCount

    CountVonCount

    Joined:
    Mar 29, 2020
    Posts:
    1
    THanks so much dude!!!
     
    kevin_x_johnson and JustJat like this.
  21. spaccini

    spaccini

    Joined:
    Jan 8, 2016
    Posts:
    1
    I FIX IT THANKS YOU
     
    kevin_x_johnson and JustJat like this.
  22. rawbarry

    rawbarry

    Joined:
    Apr 25, 2020
    Posts:
    1
    What a god! Thanks man!
     
    JustJat likes this.
  23. rguerrasa

    rguerrasa

    Joined:
    Apr 21, 2020
    Posts:
    3
    This was the only solution that worked for me. Thank you!
     
    kevin_x_johnson and JustJat like this.
  24. DeamItzOgi

    DeamItzOgi

    Joined:
    May 1, 2020
    Posts:
    1
    You are the best person alive, my beloved friend. Good luck to you and your whole family, you've made my day.
     
    kevin_x_johnson and JustJat like this.
  25. JustJat

    JustJat

    Joined:
    Jan 13, 2018
    Posts:
    2
    YES! I need to read all the answers (and the one with the most likes) before searching for hours trying the first ones. Thank you sooo much! I was losing hope.
     
    MarticusThem likes this.
  26. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    I tried on Unity 2020.1.0b11 none of the above worked on MacOS Catalina. By right-clicking on any of the the c# scripts in the project folder and selecting "Open C# Project", then I could double click going forward any script in the project folder and intellisense picked up all monobehaviour. Hope that helps :)
     
    Mikhail94 and Don_Doh like this.
  27. MarticusThem

    MarticusThem

    Joined:
    Jul 4, 2020
    Posts:
    1
    Many thanks kind sir, this worked for me. You saved me from crazyness.
     
  28. wisher_wisher

    wisher_wisher

    Joined:
    Jul 23, 2018
    Posts:
    3
    A Good Necromancer Wellplayed
     
  29. MarkWon

    MarkWon

    Joined:
    Jul 20, 2020
    Posts:
    1

    THIS IS THE SOLUTION - BRIAN SULLIVAN
     
  30. Zyrodi7

    Zyrodi7

    Joined:
    Jul 30, 2020
    Posts:
    1
    Knoxx014 thank you, I've been looking for hours.
     
  31. avantnovis_unity

    avantnovis_unity

    Joined:
    Jul 19, 2020
    Posts:
    2
    TY TY TY
     
  32. JetMerc

    JetMerc

    Joined:
    Aug 21, 2020
    Posts:
    1
    Old thread. But I'd just like to say thank you to this guy! Solution worked like a charm!
     
  33. abdelhadilammini12

    abdelhadilammini12

    Joined:
    Aug 22, 2020
    Posts:
    1
    Thanks mate, it's working
     
  34. RowdyMrB

    RowdyMrB

    Joined:
    Dec 8, 2012
    Posts:
    83
    This is the fix that worked for me. The problem started after the latest updates to Visual Studio and unity on 9/1/2020
     
    badtype likes this.
  35. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    Hey folks, PM of Visual Studio Tools for Unity here. If you're reading this post with similar issues, I am sorry for the trouble! Here are some things to consider trying first:

    Note*: If you're using Unity 2020, the integration with Visual Studio is handled by a Unity Package. Make sure this is up-to-date by visiting the Unity Editor > Windows > Package Manager. Search for the "Visual Studio Editor" package. Update it to version 2.0.2 (latest at this time). If you're using Unity 2019, there is no Unity Package to use for installation and can skip this.

    A common workaround for problems like this is to regenerate the project files. Close Visual Studio. Then, go to Unity Editor > Preferences > External Tools and click the Regenerate project files button. Next, go to Unity Editor > Assets > Open C# Project.

    If you're using Visual Studio 2017, I strongly urge you to consider installing Visual Studio 2019 for the latest improvements and feature updates to the integration for Unity. If you're using Visual Studio for Mac, consider getting the latest updates from the Check for Updates menu.

    If you're still having trouble like this, please use the Help > Report a Problem menu from Visual Studio or Visual Studio for Mac and document what's happening. Our team is eager to troubleshoot the remaining issues causing behavior like this. Please DM me if you are willing to troubleshoot this directly.
     
  36. armystone

    armystone

    Joined:
    Sep 14, 2020
    Posts:
    1
    I am unable to get the 'Unity MonoBehavior scripting wizard' to work using the CTRL-SHIFT-M combo. Is this outdated?
     
  37. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @armystone,

    Please log an issue via the Help > Report a Problem menu in Visual Studio. That keybinding is still valid, but you might be hitting a different issue preventing it.
     
  38. badtype

    badtype

    Joined:
    May 11, 2017
    Posts:
    1
    Thanks, also for me who use Unity 2020 this solution worked!
     
  39. Deleted User

    Deleted User

    Guest

    Thank You So Much It worked in VS 2019.
     
  40. Rajakaz

    Rajakaz

    Joined:
    Dec 20, 2020
    Posts:
    1

    It really worked!! Thanks a lot, man!!
     
  41. dylan1234589045

    dylan1234589045

    Joined:
    Dec 28, 2020
    Posts:
    1
    I am not able to open the project after deleting the Library and ProjectSettings.
     
  42. Helbino

    Helbino

    Joined:
    Jan 14, 2021
    Posts:
    3
    Just adding in that this solved my problem! A note that it did not work until I restarted both programs, and that I had to type in 'Monobehavior' again.
     
  43. wildjoe182

    wildjoe182

    Joined:
    Feb 3, 2021
    Posts:
    2
    Great, your fix worked for me too. Thanks!
    Unity (2019.4.19f1) with 2019 (vs community) as well.
    Without specifying this option, only one c# source file would open, no solution, no intellisense for "MonoBehaviour" for example.
     
  44. marcopriusa

    marcopriusa

    Joined:
    Apr 15, 2021
    Posts:
    2
    [QUOTE = "knoxx014, publicación: 4283710, miembro: 2783350"] ¡Soy yo! Un Nigromante al azar que pasaba, de hecho solucioné este problema en Unity y Visual Studio Link, el monocomportamiento no estaba resaltado.

    Lo arreglé con Unity> Editar> Preferencias> Herramientas externas> Editor de scripts externos> (Cambiarlo a) Visual Studio 2017 (Comunidad)

    luego reinicie ambos programas. [/ QUOTE]
     
  45. marcopriusa

    marcopriusa

    Joined:
    Apr 15, 2021
    Posts:
    2
    esta es la buena!
     
  46. unity_ctg0ujCJYRi52g

    unity_ctg0ujCJYRi52g

    Joined:
    Jun 1, 2020
    Posts:
    11
    Thank you.
    This one worked for me.
     
  47. sas67uss

    sas67uss

    Joined:
    Feb 8, 2020
    Posts:
    81
    1. In the visual studio go to solution Explorer
    2. In Assets hierarchy look for exactly folder that your script placed on that . probably you can't see the script in its folder under solution explorer hierarchy !
    IF YES then
    3_1. Right_click on exactly the mentioned folder select Add > Existing Item look for missing script in your unity project and add it . one click on some place of your script on VS editor . every thing must be OK .
    ELSE IF you see the script
    3_2. Right_click on the script delete it and re_add it .
     
  48. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
  49. DewanTheMan

    DewanTheMan

    Joined:
    May 15, 2021
    Posts:
    1
    What helped for me was inside Visual Studios on the right hand side in Solution Explorer, an assembly wasn't loaded correctly. Right click on it and say reload and it should possibly fix some of you guys' problems. :)
     
  50. TristanTheWanderer

    TristanTheWanderer

    Joined:
    Jul 22, 2021
    Posts:
    1
    Thank you, words cannot describe my gratitude.