Beginner Netcode for GameObjects Tutorial | Unity Gaming Services

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is esteva Maldonado and I am a developer advocate for Unity we're very happy that today we get to show you a little bit of how you can get started creating your own multiplayer games by following the steps that are going to be mentioned in this video you'll be able to create the space adventure demo that you see which is made of assets from our Galactic kittens multiplayer 2D game sample but let's first talk about unity's gaming services and how it can help you in the development journey of your project the Unity gaming Services consists of three major pillars the first one is the build your foundation pillar which are services that actually help you make your game and iterate as you grow a good example of this is the netco for game objects Library which is the main service that we're going to be covering today the second one is engaging with your players these are services that help help you understand the decisions that your players are making while they're participating in the experience that you're making a good example of this is the analytics service and last but definitely not least we have the grow your game pillar these are the services that help you acquire new players and also help you to monetize your game like for example in-app purchases but even though ugs can actually help you in making multiplayer games and offline games alike today we're gonna be focusing on the multiplayer side of the build your foundation pillar and will specifically Focus today on the netco for game objects multiplayer Library we use netcode as a word to describe a library or an SDK that actually helps developers to synchronize necessary gain and World data across all connected clients in a networking session and our multiplayer networking Library called netco for game objects helps you to do exactly just that this networking Library helps you to create your own multiplayer games and comes in with different synchronization techniques and components that are ready to use right out of the box at the moment Neko for game objects is better suited for small Co-op game you're not tied to this genre and you're not tied to a low amount of players it's just what's recommended at the moment a good maximum amount of players is actually around 16 and these are concurrent users that are together in a multiplayer session one useful aspect about netco for game objects is that it's actually independent from the lower level code that is the transport the transport is the actual layer of code that actually sends data in between all of the connected clients at the moment the requirements in order to use netco for game objects are the following it's best to use this library with unity version 2020.3 or newer familiarity with the c-sharp scripting environment that Unity provides will definitely help you along the way and the last requirement is really more of a way of changing your mindset when you're thinking about development because you need to start thinking differently in terms of development when you're tackling multiplayer for the first time when making multiplayer games it's good to think about that the game objects in the world actually exist both in the point will be of the server and also from the point of view of the client so it's almost like there are actually two versions of the same object in in the world but we call these two versions of the game object what is called like the server runtime and decline runtime that means when an object is actually being updated from the point of view of the server client runtime will be updating the game object from the point of view of being a client there are many high level terms that is best to get familiarized with when you're starting to make multiplayer development it's recommended to check out the high level terminology section in our multiplayer site this way you can start getting familiarized with how data gets sent from client to client in order to access the project that we're going to be using for the rest of this video please head over to the galactic kittens GitHub repository from there instead of using the main branch please change to the intro to netcode bootcamp Branch this Branch contains the necessary assets and the reduced version of the full game for you to get started from there you may actually clone the repository so that you can also later check out the assets in the main branch or for now you can download a copy now in order to get started it's good to check the package manager because there you'll actually be able to find the netcode for game objects package to install once you find it go ahead and click on the install button below and that's it for the purposes of this video I already had the netcode for game objects package installed in my Unity editor but you get the idea now head over to the scene called start here and press the play button you'll see three buttons pop up which is host in order to actually start a session join to join an already active session and quit to just quit the application I'm going to click on the host button to actually start a new networking session but I'm gonna get an error there's no network manager present let's go ahead and fix that right now so let's go ahead and fix that by creating a new game object which is going to be called the network manager this game object is gonna be holding a very very important component in the netco for game objects Library which is going to be called also the network manager now we see a lot of settings that you can actually change here that come in with this component but the very important one that we're gonna set now is gonna be the unity transport now this is a setting that says how is it that the network session is going to be connected how is it going to be started if you see we're using this IP address and that IP address means that it's going to be localhosted so the session by default is gonna be hosted by the actual computer where you're running the demo now that we've set that up let's actually run the demo again and we see that we get three buttons here which is start host start server or start client this means that you don't actually need to set up an actual UI to start testing the network manager to basically start a new session you can actually use those three buttons are in the editor but let's go ahead and use the menu and you see now that the screen has gone black now there's technically a network session already happening but it's just that right now there's no game objects nothing actually happening but this is already an active session let's go ahead and bring in our first prefab that we're going to be using our networking session to make this scene a little bit more interesting now let's go ahead and introduce our first game object of our session this player prefab field is technically an optional one but this prefab will actually be instantiated as soon as the network session starts and this is a perfect place to put a character that represents the player like the player abaton so let's go ahead and search for this player spaceship and this is gonna be our character that's gonna be representing the player when the network session starts now let's start the session again and we're going to create a new session but we get another error it which says that there's no network object assigned to it there's an expected error here but we're gonna go ahead and fix that right now let's go ahead into our simple player spaceship empty and we see here that netcode for game objects is thrown as an error it is actually warning us of a very important component that is missing which is called the network object for the purposes of this video I'm gonna manually fix this error but netcode for game objects can actually help you to automatically add this very critical component that is missing so here we are looking at the structure of the player prefab and this spaceship really contains a lot of the components that you're normally used to using in your regular games you have your Sprite renderer you have your rigid body you have your collider if you notice on the left you have another game object that represents the jet particles the jet engine particles for example and honestly this is still regular stuff that we're not into multiplayer development yet let's go ahead now and add our Network object component like I mentioned before netco for game objects comes with a lot of pre-made components for you to use in your game objects that are going to be replicated in the session the network object is really one of the most important ones because it tells the network manager that we said before what to allocate when you want to spawn a new object it is an actual unique identifier that the network manager uses to know what prefab to spawn and integrate into the session you'll see that every other prefab that we instantiate in the network session has this component as well now the next component that we're going to be adding is decline Network transform what this component does is that it actually is automatically synchronizes all of the position rotation and scale information for you there are other settings that you can adjust but let's concentrate on these check boxes that you see right here you can actually toggle which specific coordinates X Y or Z in the position rotation or scale you're gonna automatically synchronize now if this game is really a 2d game we really don't need to synchronize the z-axis because the ship is never gonna move forward or backward in the camera and also same with the rotation I am never gonna rotate in the x or y-axis maybe I'm going to rotate it in the z-axis which is actually facing the camera so I'm going to leave that in but then the scale I know that this player spaceship is never actually gonna grow or or stretch so we can actually just take all those three away one thing to note is that the client Network transform is not really part of the NGO SDK but since the network manager automatically assigns ownership of the player prefab to the client our samples team created this client Focus transform component so that you can use it in your own games you can find more information about the client Network transform in our multiplayer site and NGO documentation and last but not least we're going to add our Network rigid body 2D component this component changes all of the rigid bodies into kinematic mode in every peer except on the server in this way only the precise specific physics calculations are actually run on the server and not in every client all of this happens automatically and all you need to do is just add the component and that is it but those small changes are if player's spaceship is ready to launch and go into space let's try it out and going back to our scene everything seems to be okay let's go ahead and play the scene going back to our menu to press any key and we create a new session and there you go now we have our working spaceship that we can actually control and move around and this is the first time that we've seen a game object actually be part of an active Network session now it's all well and good that we actually have a flying spaceship but let's actually go ahead and add more character to it let's actually add another prefab that is not going to be instantiated when the session starts but at run time it's going to be instantiated whenever we shoot a bullet and that's the prefet that we're going to be looking for the spaceship bullet and when we take a look inside of the bullet we're gonna see how it looks it's just a regular beam but we see that it also has a network transform now the main difference here is that this is a regular Network transform that is part of the NGO SDK but it's meant for game objects that are going to be owned by the server this would be the opposite of the client Network transform that we saw earlier if you notice the network transform also has a lot of the emitted fields that we took away before from the network transform like we're only synchronizing the X and Y position only the Z rotation and none of the scale because same as the player spaceship this object is also never gonna grow or stretch but other than that you'll notice that this spaceship bullet also has a network object and if we scroll down we can see that it also has the network rigid body 2D same as how we did before and of course you see other components that help Define the behavior of the bullet and now that we have that set up as well let's go ahead and run the game one more time start a new session and same as before we have our moving spaceship but now if you press the space bar you'll be able to shoot some bullets from the ship to look at the hierarchy on the left you can see all of the bullet clones that were created now we have our flying spaceship and it actually shoots bullets and starting to look really cool but there's something a little bit missing because it's all just a black background right now what we saw earlier was a spaceship actually flying around in space right so let's go ahead and do that let's find and add the prefab called Parallax which actually includes four parallaxing backgrounds just drag it directly from the project View and into the scene and it'll be automatically set up and when you start the game The Parallax background actually has a behavior that moves it around and gives it that illusion of flying around in space but one cool thing to notice is that none of these objects in The Parallax actually has any network behaviors on it it doesn't have any multiplayer functionality why because these are details of the game that you don't have to synchronize exactly for every client this goes back again to the point that I mentioned at the beginning where having a new mindset is really one of those requirements that is required when entering multiplayer development okay we've gone over the basics and we've seen how to prepare a network manager for a scene and we've seen how you can actually prepare game objects for Network replication let's jump ahead now to a more complete scene that I have set up for you on this branch go to the scene called sample NGO scene you can see that it's really not that different from what we did in the previous scene we have our simple player spaceship for our player prefab in the network manager and we have the other objects that are going to be instantiated at runtime during the gameplay session let's go over now some enemies that are going to be appearing in the scene if you look at this simple enemy we see that it still has a network transform a network object component rigid body box collider all of that basically the same process as we did before so so when you're actually starting to learn NGO this is really the process like this is rinse and repeat of the same thing that we did with our first player spaceship one thing to notice is that the meteorite obstacles that appear from the right of the screen they actually do change in size so if you take a look at their Network transform settings the X and Y on the scale is checked and synchronized the C1 is actually emitted this is not the full Galactic hidden sample it is a reduced version but you can see how reducing these simple objects you can actually start to get a sense of what a game could be all you've seen me do so far is test on one single instance and all of it on the editor let's go ahead and fix that this project that you download should actually have all the build settings uh set up for you the scene that I built here for this video is the sample ngoc the one that actually contained the enemies and the meteorites as you see here I actually created a copy of the build game this is something that you only need to do on Mac in Windows you can just create the build once and open the same executable two times I'm going to open one instance and I'm gonna move it to the left the other one I'm gonna open and put it up on the right the left one as you see I'm gonna start it up as the host and the other one I'm gonna start it up pretty soon and I'll show you the same thing that I showed you on the editor but that the other one you see that I press on the join button and now I actually have two instances running together and they're all participating in the same session all of the enemy's movements are synchronized and even the objects that are spawned some of them visual effects there's a little bit of delay but remember this game is not optimized like our boss room sample we're just getting started and there's still a lot to learn and the reason I'm able to test both instances on the same computer is because the network manager is said to be hosted in the localhost I hope that in following along all these steps you've definitely gotten a bit of a sense of what it is to make multiplayer games but your development Journey really is just at the beginning we're not going to cover Advanced topics in this video but we're definitely gonna give you some resources that you can follow along and learn more first up is the actual NGO website and the multiplayer website this is definitely the best starting point for your multiplayer Learning Journey in the NGO documentation you'll find everything you need to get started from just how the SDK actually works to very important networking terminology that is best for you to get familiarized with and once you actually start to make your own games on your own development and try out the netcode SDK definitely head over to our Unity multiplayer networking Discord this is a great Community where you'll get not only the chance to talk to Unity SDK creators but also other Unity users like yourself that they're making their own multiplayer games as well and of course you can still get a lot of help from the unity multiplayer forum get to know galactic kittens as a sample on our website here you'll get a link to the GitHub repository where you can actually download all of the assets of the project and also check out the developer guide where we actually go and explain how critical components of the game actually work but again definitely do not pass up on visiting the NGO website and the multiplayer guide and last but not least again definitely go to the multiplayer Discord because this is the number one resource that actually helped us make Galactic kit as possible as game developers we like to collaborate and we like to help each other out and this was no exception so thank you for the community that actually helped us in getting this game together and thank you to the NGO Developers and for more information visit unity.com products slash netcode good luck and happy building
Info
Channel: Unity
Views: 22,498
Rating: undefined out of 5
Keywords: Unity3d, Unity, Unity Technologies, Games, Game Development, Game Dev, Game Engine
Id: dKrdrPjJG04
Channel Id: undefined
Length: 22min 32sec (1352 seconds)
Published: Tue Dec 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.