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).
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?
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.
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
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 ?
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.
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.
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.
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.
@@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
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?
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.
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!
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.
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?
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
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
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!
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?
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.?
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.)?
@@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.
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
@@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.
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
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.
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?
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 :)
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
@@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?
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.
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
Thank you so much for these tutorials! Networking tutorials are rare but so important.
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!
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).
Thanks for the kind words! I'm sure projectiles will be coming up in many tutorials that I'll be making so stay tuned :)
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.
Thanks for the kind words! Instantiating and destroying will be coming soon for sure :)
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?
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.
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
did you found what to do?
@@magjenietweten6816 sorry no :/
iv got the same problem
if(!NetworkManager.Singleton.IsHost)
{
if(!NetworkManager.Singleton.LocalClient.PlayerObject.TryGetComponent(out ScriptWithServerRpcFunction teamChange))
{
return;
}
teamChange.SetTeamServerRpc((byte)userTeamIndex);
}
Love this series already. I can’t for a video showing how to use it with Steam.
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.
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 ?
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.
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.
Any idea where the "NetworkVariableSettings" went in 1.0.0?
No documentation doesn't say anything about it either, did you find a solution?
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.
Good luck with it all! I'm sure you'll be a master in no time :)
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.
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.
@@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
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?
Can you please create a video about foot placement using Animation Rigging
Can you write a motion controller actor with a prediction? Or maybe there is a standard built-in engine?
Is this still relevant with NetCode? I can see that NetworkVariable is in a different namespace.
Please make a tutorial of Unity MLAPI with Photon realtime transport and hosting it.
Hi Dapper, I love your tutorials regarding multiplayer.
Can you try for voice sync and lobby with MLAPI?
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.
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!
@@DapperDinoCodingTutorials No problem. Just an interesting idea for a video that I have not seen covered yet.
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.
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?
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
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
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!
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?
will you be making a udemy tutorial series on MLAPI?
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.?
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.)?
Will this work on android devices too can i connect two android devices using hotspot will it be synced in android too?
when i join from 3 build and I leave the host then the third players panel didnt updates
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.
@@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.
How about saving data on the server?
Do you mean persistent storage outside of the game itself?
@@DapperDinoCodingTutorials Yes.
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
@@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.
Oh. A new tutorial.
Finally some good f'in code
Hope you enjoy!
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
most likely because it's breaking at line 12 in teamPicker
@PACeMIKE4EVER thanks, i forgot all about this comment. Thankfully got unstuck long ago :p
@@coreyduncan3427 I currently have the same problem. How did you fix it? I sadly cannot see the comment from PAceMIKE4EVER.
finally someone using bytes in network methods xD
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.
Can you make a unity tutorial on volumetric raymarching?
Definitely gotta do a tutorial on their NetworkList
Shooting mechanism?
I'll definitely be covering shooting/fps mechanics at some point once I've finished covering the basics
Thanks! It doesn't seem that hard and actually looks like it's enjoyable to work with.
It is enjoyable :) Good luck with it!
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?
Mirror or MLAPI ?
Next mirror video when?
liked it first, than watched it
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 :)
it starts and stops listening to things, it reads in his script's comments
@@aimojorma7674 thank u alot
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
Can i also change player's movement and it will sync with everyone else?
why do you do your if statements backwards? you always return after them, why not just plop the logic inside the ifs?
too much brackets
cleaner this way
@@samochreno you say that, but this is a tutorial, and a reverse if statement is harder to read and comprehend than a normal one
@@ZiplawDev i dont really think they are tho, i think its just preference
@@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?
can i create a multiplayer 2D game just like a 3D game? With the new unity multiplayer
what means subscribing and unsubscribing beacause i dont get this part
Hey Dapper Dino
Heya
whats with the other patrons, no thanks?
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.
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
What event??