How To Make A Multiplayer Game In Unity 2021.1 - Syncing Variables

  Рет қаралды 30,025

Dapper Dino

Dapper Dino

Күн бұрын

This Unity Multiplayer tutorial will teach you how to implement Network Variables to sync data between Clients and the Server. For project files access, check out the repository here: github.com/DapperDino/Unity-M...
-----------------------------------------------------------------------------------------------------------
Multiplayer Course: www.udemy.com/course/unity-mu...
-----------------------------------------------------------------------------------------------------------
Multiplayer Landing Page: docs-multiplayer.unity3d.com/
NetworkVariable Docs: docs-multiplayer.unity3d.com/...
Boss Room Sample: unity.com/demos/small-scale-c...
Roadmap: resources.unity.com/unity-eng...
-----------------------------------------------------------------------------------------------------------
Join Our Community: dapperdino.co.uk/
-----------------------------------------------------------------------------------------------------------
Just Here To Plug My Social Media Stuff:
/ dapperdino
/ dapper_dino
/ dapperdino4
/ dapper-dino-2313996518...
github.com/DapperDino
/ discord
-----------------------------------------------------------------------------------------------------------
If you liked the video then please respond with a like and a subscribe to show your support for the channel and I'll repay you by creating more tutorials for you to enjoy :D
0:00 - Intro
0:24 - Setup
1:50 - Coding
11:49 - Testing
12:26 - Outro

Пікірлер: 92
@ShiloBuff
@ShiloBuff 3 жыл бұрын
Thank you so much for these tutorials! Networking tutorials are rare but so important.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
No problem :) It is sadly true that they are rare, so I'll keep trying my best with producing tutorials to help those who are interested!
@manvondarten2632
@manvondarten2632 3 жыл бұрын
Loving these tutorials, you make it seem so simple even we can do some networking now. Would love to see how to instantiate and destroying objects.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Thanks for the kind words! Instantiating and destroying will be coming soon for sure :)
@Robertganca
@Robertganca 3 жыл бұрын
Love this series already. I can’t for a video showing how to use it with Steam.
@OnFight1997
@OnFight1997 3 жыл бұрын
This is very cool, because after getting the principle of Client/Server Side data sync, the sky is the limit, always incredibly didactic, thanks for the video. My next request would be syncing data in projectiles, (assuming there will be a lot of players and projectiles are costly in terms of size of data to send back and forward).
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Thanks for the kind words! I'm sure projectiles will be coming up in many tutorials that I'll be making so stay tuned :)
@Moonz97
@Moonz97 3 жыл бұрын
Thanks! It doesn't seem that hard and actually looks like it's enjoyable to work with.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
It is enjoyable :) Good luck with it!
@fatguystudios0com
@fatguystudios0com 3 жыл бұрын
Great video as always! I'm having some trouble connecting to a friend that is on a different network. A tutorial on this would be awesome! Keep up the good work.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Thanks! Since they are on a different network you'll need to look into how to port-forward for the host's router to allow external connections to the port that the game server is using on the transport component (7777 by default). I have considered making a tutorial for this but at the end of the day, it's going to be different for everyone so I don't think it would actually work as a tutorial.
@Blitz0909
@Blitz0909 3 жыл бұрын
@@DapperDinoCodingTutorials I think that this would still be a great video to make since there doesn't seem to any other tutorials on it. Even if it's going to be a little different for everyone, it would still be good to have some sort of an idea of what to expect! Also, I'm loving this series! This new API has convinced me to update my Unity game to be networked before it gets too far into development. It's still going to be a ton of work at this point, but these videos are a great start
@cheekz7082
@cheekz7082 3 жыл бұрын
Hi, amazing Vid, keep up the great work! And would you suggest to use NetworkVariables for shooting or what should been used for that? Would love to see a Tutorial about it
@charlesmctavish5188
@charlesmctavish5188 3 жыл бұрын
I absolutely love your videos, very informative, and there is a lot of content. I’m new to C# and unity and networking as a whole. I’m trying to make a simple 2 player online game. Any recommendations on which series to watch? Your mlapi or mirror ones?
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Both are completely fine to watch though I will be moving forward using MLAPI from now on since it is the officially supported solution (even though it is still experimental, aka, the API is subject to change) so I think I'd recommend this to someone who's starting to learn and isn't necessarily releasing a commercial game any time soon.
@RohitSharma-zy9yd
@RohitSharma-zy9yd 3 жыл бұрын
Hi Dapper, I love your tutorials regarding multiplayer. Can you try for voice sync and lobby with MLAPI?
@marian3476
@marian3476 2 жыл бұрын
Great work! I Really love your tutorials. Besides explaining very clearly, I love how expressive the names for your variables are. There is nearly no need for commenting the code! Can you maybe do a tutorial on how to measure and debug the traffic that goes across the network? Currently I am facing an issue, where I spawn two players in the scene and share their transforms with a NetworkTransform. On the Host it is working all fine, but on the Client I am experiencing a very high lag. Both instances run on the same computer. Surely I have some very inefficient code, but I have not idea on how to find out, where all the communication happens that leads to the lag. Alternatively, i would love to see how you have done your character controller for your WizardsInTraining game. Especially the synching of the rotation of the players, since this might change and needs to be updated every frame.
@walterh2113
@walterh2113 3 жыл бұрын
This definitely takes some getting used to, but it's a lot less boilerplate than having to do all of it yourself every single time.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Good luck with it all! I'm sure you'll be a master in no time :)
@Salmonman0604
@Salmonman0604 3 жыл бұрын
Definitely gotta do a tutorial on their NetworkList
@gopalpedersen9338
@gopalpedersen9338 3 жыл бұрын
Awesome tutorials! Just what i was looking for. I'm having trouble figuring out how to have a Spawner that spawns enemies which can then be killed by the players, and all of this replicated properly on all clients. Any tips or tutorials you could offer or something you might cover in the future? Thanks!
@RiorXD
@RiorXD 3 жыл бұрын
Oh. A new tutorial. Finally some good f'in code
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Hope you enjoy!
@stefan429
@stefan429 3 жыл бұрын
finally someone using bytes in network methods xD
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
I had originally used an int but then when reviewing the code before making the tutorial I thought I might as well optimise a bit and get people (including myself) into good habits for optimisation.
@lgdcompany8151
@lgdcompany8151 3 жыл бұрын
Can you please create a video about foot placement using Animation Rigging
@gamedevdanny
@gamedevdanny 3 жыл бұрын
Thanks for the tutorial? Could you do a video on a Tickbased (and/or turnbased) asynchronous game? Where each tick is like 1-3 seconds and the server broadcasts the game state every tick for the clients to simulate (movement, actions, etc.)?
@lightphoenix1522
@lightphoenix1522 3 жыл бұрын
I’m trying to show a list of joined players. In the lobby but strugling a bit. I’m also curious in switching scènes and assigning player prefabs.
@sathyarajshettigar
@sathyarajshettigar 3 жыл бұрын
Please make a tutorial of Unity MLAPI with Photon realtime transport and hosting it.
@arnaucs1534
@arnaucs1534 3 жыл бұрын
First of all, thanks for your tutorials, you are amazing. I have a question. I am making an android game but to create a server build I have to switch to pc, which messes up all my project. I tried to follow your playfab & mirror tutorial but I faced this problem. Is there a way to solve it? Can I make a server build with a separate project that has nothing to do with my game?
@JIN-TECH
@JIN-TECH 3 жыл бұрын
Can you write a motion controller actor with a prediction? Or maybe there is a standard built-in engine?
@tomsmith9707
@tomsmith9707 3 жыл бұрын
Can you make a unity tutorial on volumetric raymarching?
@whoaluis7012
@whoaluis7012 3 жыл бұрын
will you be making a udemy tutorial series on MLAPI?
@DavidZobristGames
@DavidZobristGames 3 жыл бұрын
liked it first, than watched it
@SociopathDev
@SociopathDev 3 жыл бұрын
Will this work to transfer realtime player positions? I mean while they are moving you send the position like that and others recive it to see where is the player moving
@hakanviajando
@hakanviajando 3 жыл бұрын
Hi, thanks for the video. Old Unity user here, didn't the MLAPI die? Do they update it and is it usable for a real project, without needing Photon etc.?
@vector976
@vector976 3 жыл бұрын
This is local network or sever based network which everyone can join?
@martthefart5728
@martthefart5728 2 жыл бұрын
This all works nice and well, but this project is using a local server (only accesed by your own device) Any help on how to switch it to multiple devices and stuff?
@Veevslav1
@Veevslav1 3 жыл бұрын
Hey Dapper any chance of a basic tutorial on networking basic terrain that is generated at runtime? I think it would require an array of terrain heights combined with a client side painter that paints based on Mesh angles and height. BTW thanks for the videos.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
That might be quite the challenge :) There are plenty more basic/intermediate things to cover being getting to something that advanced so I may cover it, but it will be a while, sorry. Good luck!
@Veevslav1
@Veevslav1 3 жыл бұрын
@@DapperDinoCodingTutorials No problem. Just an interesting idea for a video that I have not seen covered yet.
@enumerodev
@enumerodev 2 жыл бұрын
Hello Dino, really nice tutorials! :) I was wondering if you could help me real quick, I'm getting the "ConnectedClients should only be accessed on server" error when changing color on my charater as the client. However, the particle scripts works on both server and client. Let me know if you have any ideas! cheers
@magjenietweten6816
@magjenietweten6816 2 жыл бұрын
did you found what to do?
@enumerodev
@enumerodev 2 жыл бұрын
@@magjenietweten6816 sorry no :/
@mozzarella35
@mozzarella35 Жыл бұрын
iv got the same problem
@1Chance1Oppurtunity
@1Chance1Oppurtunity Жыл бұрын
if(!NetworkManager.Singleton.IsHost) { if(!NetworkManager.Singleton.LocalClient.PlayerObject.TryGetComponent(out ScriptWithServerRpcFunction teamChange)) { return; } teamChange.SetTeamServerRpc((byte)userTeamIndex); }
@willurquhart3D
@willurquhart3D 3 жыл бұрын
How would I go about making a variable that only the host can change? I tried using the IsHost boolean in the TeamPlayer script but it only then it only updates the variable for the host instead of only letting the host update the variable. I originally tried on my TeamPicker script but it won't allow me to have MLAPI.Connections and MLAPI.Messaging on the same script. Any work arounds?
@harshjain4256
@harshjain4256 3 жыл бұрын
Will this work on android devices too can i connect two android devices using hotspot will it be synced in android too?
@aumpalosa
@aumpalosa 2 жыл бұрын
Is this still relevant with NetCode? I can see that NetworkVariable is in a different namespace.
@whoisgliese
@whoisgliese 3 жыл бұрын
Hey man, can you answer something for me please? I'm trying to play an fps game that's already finished by me with my family. Now I only have two pcs, so I want to find a way to have two players on each pc. Is this possible?
@nathanbarraud4349
@nathanbarraud4349 3 жыл бұрын
I'm a very early beginner with multiplayer so sorry if my question is stupid, how do you use rigidbody in multiplayer ? How to sync the movement of 2 objects falling and colliding ?
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
It depends on your use-case but a good place to start would be having the rigidbody simulate physics on the server only and then use the NetworkTransform component to sync its position to all the clients.
@voltototo
@voltototo 3 жыл бұрын
I had the same issue and solved it by letting some player who wants to do something with a rigidy body send a serverRPC and in that ServerRpc call a clientRpc, which tells the clients to do the phyiscs.
@rucesocial8004
@rucesocial8004 3 жыл бұрын
Mirror or MLAPI ?
@VyvyanTheGreat
@VyvyanTheGreat 2 жыл бұрын
Any idea where the "NetworkVariableSettings" went in 1.0.0?
@niekzandt6929
@niekzandt6929 2 жыл бұрын
No documentation doesn't say anything about it either, did you find a solution?
@derekdecramer2919
@derekdecramer2919 3 жыл бұрын
Next mirror video when?
@SpaceKebab
@SpaceKebab Жыл бұрын
an AI responds to how it thinks your code works: The TeamPlayer class derives from the NetworkBehaviour class, which is provided by Unity Netcode and allows this component to interact with the network. It has a serialized field teamColourRenderer that references a renderer component attached to the same game object, and an array of colors called teamColours. It also has a NetworkVariable called teamIndex of type byte, which is used to store the team index of the game object over the network. The TeamPlayer class has a method called SetTeamServerRpc, which is marked with the [ServerRpc] attribute. This indicates that it is a remote procedure call (RPC) that can be invoked by clients, but will only be executed on the server. The RPC sets the value of the teamIndex NetworkVariable to the value of the newTeamIndex parameter, but only if the value is less than or equal to 3. The TeamPlayer class also has an OnEnable and OnDisable method, which are Unity messages that are called when the component is enabled or disabled. In these methods, the OnTeamChanged method is registered or unregistered as a delegate for the OnValueChanged event of the teamIndex NetworkVariable. Finally, the OnTeamChanged method is called when the value of the teamIndex NetworkVariable changes. It updates the color of the teamColourRenderer based on the new team index. However, this is only done on the client, as indicated by the check for IsClient. tell me what you think
@navinkumar7370
@navinkumar7370 3 жыл бұрын
Shooting mechanism?
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
I'll definitely be covering shooting/fps mechanics at some point once I've finished covering the basics
@coreyduncan3427
@coreyduncan3427 2 жыл бұрын
Having an issue with updating sprite renderer for 2D game, code is virtually the same besides targeting sprite renderer instead of Renderer but I'm getting an error saying the function should only be called by the server, not connected clients, any thoughts? Thanks... works fine for host but clients aren't updating/getting an error, also doesn't sync on re-entering game
@coreyduncan3427
@coreyduncan3427 2 жыл бұрын
most likely because it's breaking at line 12 in teamPicker
@coreyduncan3427
@coreyduncan3427 2 жыл бұрын
@PACeMIKE4EVER thanks, i forgot all about this comment. Thankfully got unstuck long ago :p
@_MauMau_
@_MauMau_ Жыл бұрын
@@coreyduncan3427 I currently have the same problem. How did you fix it? I sadly cannot see the comment from PAceMIKE4EVER.
@lilbayg9864
@lilbayg9864 3 жыл бұрын
hi , i searched a lot to find out what this "-= " does in your scripts,i know what it does with ints and floats but you used that between voids, i'll be thanks full if u help me with this :)
@aimojorma7674
@aimojorma7674 3 жыл бұрын
it starts and stops listening to things, it reads in his script's comments
@lilbayg9864
@lilbayg9864 3 жыл бұрын
@@aimojorma7674 thank u alot
@caranjeetkumar6986
@caranjeetkumar6986 3 жыл бұрын
when i join from 3 build and I leave the host then the third players panel didnt updates
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Thanks for mentioning that, I'll have a look into that for myself when I get some free time to see if I can replicate it.
@caranjeetkumar6986
@caranjeetkumar6986 3 жыл бұрын
@@DapperDinoCodingTutorials I am a big fan and i am making this game too, The game is running fine accept this problem that i have written in the comment. Please see the problem if you have time.Niceeee to talk to you.
@cho.gath789
@cho.gath789 3 жыл бұрын
Hey Dapper Dino
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Heya
@whatamiwitnessing1003
@whatamiwitnessing1003 3 жыл бұрын
How about saving data on the server?
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
Do you mean persistent storage outside of the game itself?
@whatamiwitnessing1003
@whatamiwitnessing1003 3 жыл бұрын
@@DapperDinoCodingTutorials Yes.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 3 жыл бұрын
You can either use PlayerPrefs (very simple but not recommended for complex data), saving a file locally on the server (would only work if that is the only server there is), or using a database/3rd party service like playfab that the server can read to/write from
@whatamiwitnessing1003
@whatamiwitnessing1003 3 жыл бұрын
@@DapperDinoCodingTutorials I was thinking about a database, preferably MySQL with unity stand-alone server in place of client hosted. Do you have any courses on this? I don't mind paying if that course is available on a platform.
@rafaeldicker3644
@rafaeldicker3644 3 жыл бұрын
Can i also change player's movement and it will sync with everyone else?
@felipeliberado
@felipeliberado 3 жыл бұрын
can i create a multiplayer 2D game just like a 3D game? With the new unity multiplayer
@zakku1653
@zakku1653 2 жыл бұрын
what means subscribing and unsubscribing beacause i dont get this part
@wiljagerhardt1219
@wiljagerhardt1219 3 жыл бұрын
whats with the other patrons, no thanks?
@ZoidbergForPresident
@ZoidbergForPresident 3 жыл бұрын
I know it's not important here but wouldn't it work if the team colours were a ScriptableObject instance? So, no need to copy the list of colours and make sure they are identical and also no need to hardcode the maximum index.
@ZiplawDev
@ZiplawDev 3 жыл бұрын
why do you do your if statements backwards? you always return after them, why not just plop the logic inside the ifs?
@samochreno
@samochreno 2 жыл бұрын
too much brackets
@samochreno
@samochreno 2 жыл бұрын
cleaner this way
@ZiplawDev
@ZiplawDev 2 жыл бұрын
@@samochreno you say that, but this is a tutorial, and a reverse if statement is harder to read and comprehend than a normal one
@samochreno
@samochreno 2 жыл бұрын
@@ZiplawDev i dont really think they are tho, i think its just preference
@Mukna132
@Mukna132 Жыл бұрын
@@ZiplawDev This is generally considered best practice. It's something called a guard clause. It makes sure it has what it needs before running any 'real' logic. For example, if you have an if statement with a large amount of logic inside it and then waaaaay down inside that, you have another if statement that fails and all it's doing is checking if something is of a certain value. You have wasted cpu time by running all that logic beforehand. Guard clauses will return you from the function well before it would have failed otherwise. Does that make sense?
@mickmickymick6927
@mickmickymick6927 3 жыл бұрын
Didn't work. If I change the variable, then a client connects, the client doesn't see the new variable. Anyone else have this problem? Edit: I got it, by subscribing to the event in Start() and not unsubuscribing. I look forward to seeing what future hidden errors I have caused myself by doing this
@cuentaprueba8332
@cuentaprueba8332 2 жыл бұрын
What event??
How To Make A Multiplayer Game In Unity 2021.1 - Object Spawning
11:29
Using Image Recognition to DESTROY Fruit Ninja
10:08
CodeNoodles
Рет қаралды 603 М.
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 76 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 56 МЛН
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 60 МЛН
Multiplayer Game Architecture in Unity
15:21
Shrine
Рет қаралды 151 М.
So you want to make a Game Engine!? (WATCH THIS before you start)
14:39
Giant Sloth Games
Рет қаралды 281 М.
How To Make A Multiplayer Game In Unity 2021.1 - Boss Room Sample
14:50
How to Make an Indie Game Trailer
14:32
Game Maker's Toolkit
Рет қаралды 1 МЛН
Adobe is horrible. So I tried the alternative
25:30
Bog
Рет қаралды 760 М.
How to ACTUALLY get into Gamedev
14:01
DaFluffyPotato
Рет қаралды 704 М.
Get Started with Photon & Unity: Clients, RPCs, and More!
35:34
Multiplayer In Unity Made Simple || Netcode For GameObjects #1
12:04
Bob Nystrom - Is There More to Game Architecture than ECS?
23:06
Roguelike Celebration
Рет қаралды 196 М.
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 76 МЛН