Godot 101: C# Development Basics

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everybody and welcome back to another episode of good dough 101 uh today we're going to be covering a simple topic which is the basics of developing your game in godot using c-sharp in the the mono framework uh there's many reasons why you might choose to use c-sharp for example the performance is you know slightly better or can be roughly up to four times better uh you know not an order of magnitude better but still going to be better performance than using gd script but uh a perhaps bigger motivation to use c sharp is that it's a more standard programming language not a lot of places use gd script unless they're exclusively using it for godot programming whereas very many companies will be looking for c sharp developers other game engines used c sharp and in general it's a better practice to use c sharp as you'll learn more about regular c type programming languages whereas godot is more of a offset of python which itself is a c-type programming language but it's not quite python so what you're using is pretty specific to godot unless you switch over to c sharp where then your knowledge and what you learn is more applicable to software engineering as a whole um yeah so we'll be covering how to use you know how to set up godot to use the mono c-sharp support as well as how to set up an ide or hopefully two on how to build and develop and debug your godot games that way you should be able to you know write your first hello world script and or hello world controller and be able to go from there as you develop so we're not going to really cover the basics of c sharp programming and syntax as a whole it's going to be more of just making a a few brief changes to an existing controller but we're not really going to be going through what is c sharp what's the syntax what are the things it can do um there's many c sharp tutorials that you can go watch online or read online so i recommend those but that's not going to be the topic of this however if you are trying to learn c sharp and you're pretty new to it kedo is a great way to learn so the first step is you're going to download the mono version of godot the standard version which is what you'd get from for example from steam or if you're used to downloading your regular the standard version isn't going to have the support that you need so you've got to use the mono version make sure you pick the binary that you're interested in developing and publishing on for example i'm using 64-bit in rare cases you might need 32-bit but most applications in most platforms support 64-bit once you download it uh you'll get a zipped file and for example it'll look something like this and inside you'll have the executable as well as the for example the compile debug and release builds and things like the mono framework and even some other tools but we don't need to worry about those the primary thing is i've already downloaded it and unzipped it and you'll have a folder like this now where you put godot doesn't matter too much what i would recommend is that you put it either somewhere where you can keep track of the version if your game relies on version for example 3.2.3 you don't want to be switching it because it might cause weird behaviors or even break your game build so either put it in a place where you can keep track of which version and point to it or since it is only roughly 150 megabytes in size i'm here if you've got the disk space which i do it doesn't really hurt to put it in your game folder so for example i have a folder called my c-sharp godot game and i have a bin folder and so i unzipped it into this guy here you don't have to do that but it does make it a little easier to know exactly which version of godot your game is relying on and if you ever need to update it and you can update this folder without affecting other games it's up to you but for this demonstration i put it in here once you have this folder the next thing i did is i made an empty project folder there's nothing in here you don't have to do this but i recommend doing it just to help separate your project from the binaries this would also be a place where to put builds if you're building your game or even asset repositories for for you know your larger photoshop documents or something that wouldn't necessarily go into the game but might be used to produce assets for the game now uh and of course the name bin doesn't have to be bim that's just the name i gave it to so once you have this project folder set up we're going to go in and launch godot launch it just like normal godot comes up like you would expect and we can make a new project so let's put that new project in our new folder my game in project select this and you can name it whatever c and we don't worry about the render so we'll create and edit and when you create the game first thing that's going to pop up is a little message letting you know that the support is for c sharp being developed um so please submit issues or anything that comes up so that way you can help the development of godot and other than that your your kudo editor looks like everything you would expect there's nothing significantly different here the main difference is and we'll go over to it there'll be a few more changes to support the mono project so the first thing you're going to want to do is go up into editor and click editor settings and we're going to be trying to do two things first we're going to scroll all the way down to the bottom where we have mono and you want to make sure that you configure your editor to be your preferred editor there's a list of options here visual studio is a very common one i don't recommend mono develop but it's perhaps been improved but i imagine most users going to prefer either visual studio code visual studio or jet brains writer personally i prefer jetbrains writer so we'll go over the setup for that one first but visual studio code is a free alternative and it's not quite as powerful as jetbrains or visual studio but it'll get the job done so when we configure the editor that means it'll launch that editor when we try to edit a script the next thing we have to configure is go down to the builds and same thing it's going to be looking for which annas build you're going to use jetbrains writer comes installed with ms build so you can select that one but if you want to use visual studio you'll have to install the visual studio build tools that is actually relatively straightforward to do there is a link for it in the c-sharp basics documentation and here you can download the build tools which i've already done and started running and there's a net framework 4.5 which is what the documentation recommends that you install so if you're going to go the visual studio route either visual studio code or visual studio proper you'll want to use this framework but otherwise you can use the one built into jetbrains writer if you're using that now jebrain's writer i just want to note unless they have a free version it is a paid subscription so you'll probably um want to go with the free visual studio code if you're if you're a new developer excuse me um but me for example i'm used to the jetbrains ides so i prefer those um and by the way everything i'm going over is in the c-sharp basics documentation but i know that it helps a lot of people including myself to have a video that sort of walks through with you so for right now let's assume that we're going to use jet brains so we're going to make sure that the editor and the builds are both using jeopards and we'll close the settings now the next step that we'll want to do is we're going to create a very basic scene so i'm going to go to node 2d make a scene and i'll make a node called player very simple now the first step is let's save our scene and then we'll want to attach a new node script and we'll want to make sure we select c sharp by default it should have gd script let's use c sharp and you don't have to mess with anything else here one thing to note is that i believe unless it changes the name of the script in the name of the class inside of the c sharp file have to match the node so don't play around with the names too much because you can run into some trouble there so we'll hit create now the reason why we want to create the node in the script first is that godot is actually going to go in so let's go back to the project folder it's going to go in it's actually going to create things like this project and solution as well as your script here so it's actually going to do some initialization of the project for you so we want to create that first node in that first script just to set everything up now what we want to do next is set up our ite so i've already installed jetbrains uh writer you would also install visual studio if you prefer that so uh let's launch writer and then we'll go over the configuration for writer all right here comes writer so what we'll do is we'll just open and we can go to our game our product folder and we can just select the solution you can also just select the project folder and that'll do the same thing but for now let's just go with the solution and so here's our id it's loading everything up now here is our default player controller that was generated by godot when we made the new script a couple things to note is that we've got some scary red text indicating that godot and system can't be found excuse me and that's because we haven't set up our ide quite yet so we're going to do a few things first we'll go to file go to settings and once we're here we're going to go to excuse me build execution deployment and go to tool set and build in here we're going to double check the ms build version there's a couple of versions here you can use whatever's auto detected chances are it'll it'll be perfectly fine but for example you could also switch to say the built-in writer version of ms build if you wanted to these all three are using some 16.0 version of it so they should all do the same thing but just to make sure if you don't have one that's already installed through net you'll probably want to use the built-in jet brains one the next thing we'll want to do is go to the plug-ins so settings plug-ins and we'll just search for ditto and in here we're going to want godot support this here is what allows the editor to uh integrate with godot and run godot so make sure you have that installed and you'll probably have to reboot the editor for the plugin to take effect and once you have that we'll hit save so that gives us a few things like for example learning to use how to how to run the builds for editor and player but we'll see that it's still complaining about cadellan system and that's because it doesn't know where the libraries are for godot to fix that we'll go to our solution explorer and we'll go down here to dependencies right click add reference and we'll add from now this lets us select the dlls to use for our references here and so we're going to go back to my c sharp game bin into the godot version that you got kado sharp api debug and godotsharp.dll and open that well also just for good measure i'm not 100 sure if this is necessary but we'll go into the api release godot and add that and for some reason sometimes it doesn't always take you can click on these and click add here and that should add those references to the project while this is working we can also go over the visual studio code setup so visual studio code you can install it just like normal once you've got the project open the first thing we want to do or sorry once you've got the tool open first thing you'll do is go to the extensions tab here and you can search for two things the first is c sharp that gives you c sharp support in visual studio so make sure you install it which i already have the next thing is to look forward to though you'll see here there's a c sharp tools for godot this helps with things like debugging launching building etc and so you want to install that as well there's also this godot tools which i think might be a dependency but i think this is the one you're looking for c sharp tools for godot install that and you'll probably have to restart visual studio code to get the plugins updated once you have that you can open a folder once again we can go to our c-sharp game project and open this project folder when it does we'll see our solution here and we can even bring up our script here it is and finally if we want to run this there's multiple ways to do it the first is to make sure you have godot already running and this is visual studio code specific once you have godot already running you can click the run tab here make sure you click create launch.json if you haven't already it'll try to create a launch.json for your project once again this is for visual studio code specifically this please all right sometimes you might have to open up the command palette which is ctrl shift p intel to run judo and uh here it has our launch.json i forget if that's it's a little tricky so it can take a second for it to come up but now that we have launched.json if we go back to the run tab you'll see we have a number of options here we have launch which will launch a new editor attach which allows us to attach to an existing editor and we have play an editor here which will play the scene or in you know in the existing editor that we've got running i recommend that one and so for example let's make a simple script that does hello world very simple we'll say godot.print to the console some message which is hello world we'll save it and we'll play it in the editor we do that first thing we're going to say is hey we don't have a main scene so let's select it let's pick our player scene as our main scene it'll build the solution and i accidentally added a typo there um so once i've made a change like that you can go into this mono tab down here at the bottom and click build project but there's also a helpful button up here in the top right that you can click to rebuild and left another typo in there there we go and so this uh this sort of highlights a few of my frustrations with visual studio code in that the way that i have it set up at least it's not very good at syntax highlighting and auto completion so i'm having a lot of issues where i'm just adding typos in my code and it doesn't work who would have guessed all right so the project is built it's ready to go so what we're going to do is we're going to add a breakpoint and play our game in the editor here we can see it's rebuilding and we want allow access and what we want is to see hey we've hit that breakpoint in visual studio we've got things like this object we've got the file name all these variables that are very useful for debugging i do prefer this debugger over the built-in gado debugger and we can see that we've hit the breakpoint here on the hello world i will get rid of the break point and hit continue and we'll see that hey it printed hello world to the console so there we go we've we've built our first script here in c sharp once again uh i'll probably do most of my personal development here in jeff brain's writer but uh visual studio code is if you're a beginner it's a great ide and it's useful for more than just programming c sharp i use it for things like viewing json files or csv files there's a ton of helpful extensions to help with pretty much anything you're working on you can even do things like python development and i bet you there's a way to do gd script development in visual studio code i just haven't set that up before so now that we've got this set up uh i do want to point out just a few common things that people probably want to do for example the first common one that a lot of people do is exporting a variable to do that it's going to look a little different than we have in godot but we'll put this export annotation here in the brackets we'll say let's export a new public variable called let's make it an integer called player health and we'll define it starts at zero so here we'll see that player doesn't have that yet because we haven't rebuilt the project so let's hit build builds the solution and hey our player now has a script variable called playerhealth as you can see it's an integer not a float and we can mess with it perfect another common thing people might want to do this is going to be a little different than in gdscript is let's make a new node and let's call it other let's give it a new script c sharp we'll create it and this one we'll look at here we actually don't need to do anything to this but let's say we wanted to reference let's go back to this let's say we wanted to reference this child node in our player script that way we could do that we make a private uh other type this other is just the class that we created with this other script here other is just a node 2d so very simple we'll make a private other so the type is other we'll call it my other oops and we'll not initialize it because it doesn't get initialized until the on ready has been called for our project so what we'll want to do oops let's close this what we'll want to do is in this ready override function here we can then do something like uh my other equals get node and look in other like that and let's set a breakpoint there and so the hope is that by running this we'll be able to get the other node from here so let us run and play it in the editor editor will start building again hopefully we didn't have any more syntax errors looks like we did oh and that's because i missed something so get node gives us just a node type but we can also give it a template which says we want to know that is templated into some other type so let's say let's get a node of type other at the path other let's stop it and play in editor again there we go all right we've hit the breakpoint we can use our debugger to step over now we have a my other let's go check it out so in here i'm going to scroll down so we can find it yeah well what we can do instead is add this to our watches and we see it found a node and we can even look and see hey there's the name as my other um and if we had any other variables here we could find those so for example let's open that up and just do something like public um the other other my health there we go let's stop run play the editor again it'll rebuild and then once it's done we should hit the breakpoint step over now we have my other and hey my health is a hundred so we know that we are accessing this other class so there we go we've done a few of the basics such as exporting the variable and seeing that exported variable in the editor we've been able to access other nodes and most importantly we'd be able to do some of the debug stuff such as printing a message in the console or most importantly setting up the debugger with a breakpoint so that way we can debug our program yep so with that uh we basically covered the the bare minimum for how to set up and run a c-sharp project uh just remember that everything i covered is here in the c-sharp basics so don't don't think i invented all this that's all listed down here and then there's also a couple tutorials on c-sharp specific features api differences that i highly recommend you go through to figure out what's going on under the hood and of course the style guide's going to be a little bit different than the gt script that you might be used to so please read through these i'm not going to cover them because you can spend all day going over what i do and don't agree with but otherwise uh these pages here in the doc scripting c-sharp these are going to help you out a lot so yeah i think that just about wraps up this godot 101 video if you like this video please don't forget to share it and subscribe that really helps get the visibility out and if you'd like to see more i want to know about it so please like and subscribe so i know what you guys are looking for and if you have any more ideas of topics you'd like me to cover videos like this or if you want me to cover more specific c-sharp implementation of things please leave a comment below and i'll review all of them and hopefully we can see what you guys are after and we can get a couple more videos up that help you guys if you're trying to do some more c-sharp development or anything else in good out so yep thank you
Info
Channel: Godot Academy
Views: 3,697
Rating: undefined out of 5
Keywords: godot, gamedev, csharp, mono, development, software, c#, programming, tutorial, guide, learn
Id: BpDOpc0tHM0
Channel Id: undefined
Length: 24min 2sec (1442 seconds)
Published: Sun Mar 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.