Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Visual Studio doesn't compile the code while editing.

Discussion in 'Scripting' started by Quidney, Oct 20, 2023.

  1. Quidney

    Quidney

    Joined:
    Sep 8, 2020
    Posts:
    10
    I had Visual studio already installed with .NET for C# Console and Form applications.
    After that I installed unity, and added visual studio as the external code editor in Preferences -> External Tools.
    I opened up a script and realized it doesn't compile. I closed visual studio and unity.
    Opened Visual Studio Installer, Clicked on modify, added game development with Unity.
    Went back to Unity, opened external tools, refreshed the visual studio, regenerated project files.

    Opened the script by double clicking on Unity, it opened up Visual Studio, I made an error on purpose.

    Code (CSharp):
    1. if (timerInterval > 0 &&) // AND needs another statement or check
    2. {
    3. //Code
    4. }
    Visual Studio shows no errors, Unity does.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Did you actually execute the „Build Solution“ or similar menu item in VS in order to start compilation?
    VS doesn‘t automatically start compilation when you save a file.
     
  3. Deleted User

    Deleted User

    Guest

    Try opening the C# project in Assets/Open C# project in the Unity editor instead.
     
  4. Deleted User

    Deleted User

    Guest

    Visual Studio should react to the error on typing. No need to compile. :)
     
    Quidney likes this.
  5. Quidney

    Quidney

    Joined:
    Sep 8, 2020
    Posts:
    10
    There's Attach instead of Compile, and it should be automatically telling me my errors.
    That's what it did on another computer when I used to code there.
     
  6. Quidney

    Quidney

    Joined:
    Sep 8, 2020
    Posts:
    10
    You mean "Right click -> Open C# Project" in the asset browser?
    If so, it does the same thing. And my errors aren't visible until I save the code and go back to unity.
     
  7. Deleted User

    Deleted User

    Guest

    Well, there's probably a problem with Visual Studio then. Are you sure you installed every component needed for it to work properly with Unity? I'm not using Windows, so I don't remember exactly what needs to be installed but you should take a look at that: https://learn.microsoft.com/en-us/v...-visual-studio-tools-for-unity?pivots=windows.
     
  8. Quidney

    Quidney

    Joined:
    Sep 8, 2020
    Posts:
    10
    Yes I already installed it. (It only shows "Game development with Unity" to install in that link)
    I will try "repairing" and report back if it works.
     
  9. Quidney

    Quidney

    Joined:
    Sep 8, 2020
    Posts:
    10
    Repairing has no effect on this problem.

    Visual studio still doesn't give out errors.
    When I save and go back to unity though, it tells me the errors.

    Momentarily I do not think there's a difference between using Np++ and Visual studio since they both make code suggestions, but they do not understand errors.
     
  10. Deleted User

    Deleted User

    Guest

    Just in case, did you restart your computer after installing, repairing, etc?
     
  11. Quidney

    Quidney

    Joined:
    Sep 8, 2020
    Posts:
    10
    Yup. Ofc