How to set up Visual Studio Code for Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is adam i get a lot of questions from my videos on how to set up visual studio code for development with unity ps code is an advanced code editor that can be used for nearly any kind of software development because of how extensible and customizable it is it is my personal choice for all the programming i do across various technologies and languages so let me show you exactly how to set it up for unity one important thing to note here is that visual studio and visual studio code are not the same thing these are two distinct pieces of software developed by microsoft visual studio is a full ide for developers whereas visual studio code is only a code editor however because of the many supported extensions offered in vs code we can customize it to suit the needs of nearly any kind of software development it is for this reason that many developers use vs code over the full-blown visual studio it's much more lightweight and much more accessible the first thing we have to do of course is download vs code if you don't already have it it can be downloaded from code.visualstudio.com you might also need to download the.net core sdk since unity applications are dot at applications you can download it from.net.microsoft.com the sdk includes everything needed to run and build.net applications however unity comes with an open source implementation of dotnet this is not needed to run your unity game but rather to solve any issues with vs code not working correctly for your unity project i would only worry about downloading this if you end up running into issues after following the remaining steps in the video after you have installed vs code go ahead and open it up and let's install the c-sharp extension c-sharp is the programming language used in unity projects so we need to install the extension if we plan to write code for our games envious code look for the extensions menu on this side panel over here and hover over these icons and find the one called extensions if you don't see those you can also go to the view menu and then extensions once you've opened this up let's search for c sharp find the extension by microsoft it should have a blue check mark and it'll have millions of downloads because it's a really popular extension used by a lot of different developers let's go ahead and install that should only take a moment and that's it that's all we need to do in vs code itself the remaining setup will happen in unity we need to install a unity package that provides support for the visual studio code editor the only requirement is that you're using unity 2019.2 or higher since that is the version when the package first became available there are still ways to set up vs code for even older versions of unity but this tutorial won't cover them in entirety many of the steps will still be the same though here i have a completely new empty project but you can still do this if you already have an existing project navigate to the menu window package manager from here let's go to this drop down and go to in project this will list out the packages that you already have installed in your project you can see i already have visual studio code editor installed it actually came installed by default when i created the project i did not install this myself it already was pre-installed if it's not pre-installed go to the unity registry and here you can search through all of the different packages that unity provides and you can install any of them find the one called visual studio code editor not to be confused with visual studio editor once again those are two different pieces of software visual studio code editor and install this i believe the button will show up down in the bottom right hand corner in my case since it's already installed there's a remove button this is where you would go to install it if you ever need to update the version of it you can also do that here another way you could install a package is doing it manually by editing a specific file in every unity project so here if i open up my project find the folder called packages and then open the file in some kind of text editor or code editor called manifest.json this json file lists all of the different packages that you have installed in your project a lot of them are just built-in modules that unity provides you can also see here com.unity.ide dot vs code this is that vs code package that we need installed once again in my case it's already installed but you can manually enter this in if you need to you'll provide whatever version of the package you want and the next time you open up unity it will automatically install this package that is an alternative way you can install a package kind of by manually editing this file next we need to tell unity which editor we are using this will make it so anytime we open up a script in unity it will automatically open up with our editor of choice let's navigate to the menu edit preferences let's select the external tools tab then in the external script editor drop-down we can choose visual studio code after that loads let's click the reset argument just so the args gets set back to the default value in case it's not already set for you let's also click the regenerate project files button this will regenerate the solution file and cs project files that are used by vs code to know how to compile your code this is important for intellisense and other editor features to work correctly it's also really important for those of you who are doing this in an existing project if you ever run into problems with your editor or with intellisense not working correctly it's not picking up your classes or anything i usually come in here and i click the regenerate project files button and that usually fixes the problem after you do this you'll want to close vs code and reopen it and then it should work correctly there are some other settings here that you can change but in most cases you probably don't need to in the several years that i've been using vs code with unity i've never needed to actually change any of these settings all right all we need to do now is verify that everything is working correctly you can do that by opening up a script file and just testing it out now since this is a brand new project for me let me go ahead and create a new script real quick when i open this up it should open up with vs code let me double click it sure enough it opens up with vs code even brings up an output panel here indicating that some c-sharp dependencies were installed for my project great in the very bottom left-hand corner is this little flame icon and it indicates that omnisharp server is running omnisharp is the set of services that run for c-sharp that's what's handling all your intellisense and other things provided with the c-sharp extension that we installed earlier you can even see in here powered by omnisharp that's good we want that i believe if your project doesn't open successfully this will maybe even show um like red that there's an error and i think if it's yellow it'll indicate that it's like currently working on something or something's like it's loading essentially we can actually click that and it'll give us the log of everything it's been doing we could read through this but we don't need to but the most important thing in here is that it says successfully loaded project file great that's what we want to see if you are having problems with your intellisense in vs code check this log it'll show that there's some kind of error if that's the case if it's actually not working the way it should it'll show an error or a warning or something along those lines and this is where sometimes we just need to regenerate the project files sometimes it's it's just a matter of going to edit preferences external tools and regenerating these project files and so that'll regenerate the solution file in the cs project file and sometimes can help if there's any problem if you run into any problems and it's not loading correctly make sure you close vs code and reopen it if you do that we of course can verify that this is actually working too if i just start typing in something so i can say for example game object i can already see different functions and and properties here that are available okay component yep these are all unity's functions provided so all the intel sense is working the documentation is working i can click into different objects like mono behavior and i can inspect the code provided by unity so everything is all good there this looks to be working exactly how expect another way you know that this is working is because it opens your entire project here oftentimes if it's not working it might just open up that one script completely by itself but we want to open up this as part of the larger project right and so here i can see all of my my all the files for my unity project and as i need to if i had other scripts in here i can click into them and edit those and so on sometimes when vs code opens it will ask you to select the project solution as illustrated in this picture here you'll want to select the c sharp solution file so it loads your entire unity project correctly you'll notice in the bottom left-hand corner it says myproject.sln or sln stands for solution so the solution kind of defines the entire project it is like the all the files and grouping for the entire project all the different assemblies and cs project files that represent my project and so because this is loaded my entire project is loaded not just the one individual script and that is necessary if you want your scripts to be able to be aware of all you know the unity classes and functions and so on all your intellisense and everything like that this looks good this is all working correctly and that is actually it now notice here actually before i finish whenever we make a change to a file so let's go ahead and just write something real quick let's say um we'll just throw a debug statement eboglog true when i save this file and i minimize when i go back to unity it's automatically gonna recompile and everything should be good so that's also important whenever you update that file you should go back unity see that it recompiles and so on if you have any compiler errors that will show up in your console and you can fix them as necessary i really appreciate you watching this tutorial and i hope you learned a thing or two along the way give the video a thumbs up or down to let me know how i did subscribe to the channel for more videos just like this one and leave a comment recommending what you would like to see next if you want to support my work even more you can become a patreon member to receive exclusive benefits including access to the unity assets that i develop link in the description of the video thank you for watching see you in the next one [Music] you
Info
Channel: Zigurous
Views: 108,552
Rating: undefined out of 5
Keywords: unity tutorial, unity, how to use unity for beginners, how to make a game, unity 2d tutorial, game development, how to make a game in unity, unity 3d, unity 2d, game dev
Id: 1saf4ahn-ek
Channel Id: undefined
Length: 12min 10sec (730 seconds)
Published: Fri Feb 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.