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

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 91

  • @ShiloBuff
    @ShiloBuff 3 года назад +27

    Thank you so much for these tutorials! Networking tutorials are rare but so important.

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  3 года назад +8

      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!

  • @OnFight1997
    @OnFight1997 3 года назад +9

    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 года назад +4

      Thanks for the kind words! I'm sure projectiles will be coming up in many tutorials that I'll be making so stay tuned :)

  • @manvondarten2632
    @manvondarten2632 3 года назад +11

    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 года назад +1

      Thanks for the kind words! Instantiating and destroying will be coming soon for sure :)

  • @charlesmctavish5188
    @charlesmctavish5188 3 года назад +4

    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 года назад +4

      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.

  • @enumerodev
    @enumerodev 2 года назад +3

    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 2 года назад

      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);
      }

  • @Robertganca
    @Robertganca 3 года назад +2

    Love this series already. I can’t for a video showing how to use it with Steam.

  • @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.

  • @nathanbarraud4349
    @nathanbarraud4349 3 года назад +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 года назад +4

      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.

  • @VyvyanTheGreat
    @VyvyanTheGreat 3 года назад +2

    Any idea where the "NetworkVariableSettings" went in 1.0.0?

    • @niekzandt6929
      @niekzandt6929 3 года назад

      No documentation doesn't say anything about it either, did you find a solution?

  • @walterh2113
    @walterh2113 3 года назад +11

    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.

  • @fatguystudios0com
    @fatguystudios0com 3 года назад +2

    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 года назад +1

      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

  • @martthefart5728
    @martthefart5728 2 года назад +1

    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?

  • @lgdcompany8151
    @lgdcompany8151 3 года назад

    Can you please create a video about foot placement using Animation Rigging

  • @JIN-TECH
    @JIN-TECH 3 года назад

    Can you write a motion controller actor with a prediction? Or maybe there is a standard built-in engine?

  • @aumpalosa
    @aumpalosa 2 года назад

    Is this still relevant with NetCode? I can see that NetworkVariable is in a different namespace.

  • @sathyarajshettigar
    @sathyarajshettigar 3 года назад +1

    Please make a tutorial of Unity MLAPI with Photon realtime transport and hosting it.

  • @RohitSharma-zy9yd
    @RohitSharma-zy9yd 3 года назад

    Hi Dapper, I love your tutorials regarding multiplayer.
    Can you try for voice sync and lobby with MLAPI?

  • @Veevslav1
    @Veevslav1 3 года назад +1

    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 года назад +1

      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.

  • @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.

  • @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?

  • @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

  • @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

  • @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!

  • @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?

  • @whoaluis7012
    @whoaluis7012 3 года назад

    will you be making a udemy tutorial series on MLAPI?

  • @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.?

  • @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.)?

  • @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?

  • @caranjeetkumar6986
    @caranjeetkumar6986 3 года назад +1

    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.

  • @whatamiwitnessing1003
    @whatamiwitnessing1003 3 года назад +1

    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.

  • @RiorXD
    @RiorXD 3 года назад +1

    Oh. A new tutorial.
    Finally some good f'in code

  • @coreyduncan3427
    @coreyduncan3427 3 года назад

    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 3 года назад

      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_ 2 года назад

      @@coreyduncan3427 I currently have the same problem. How did you fix it? I sadly cannot see the comment from PAceMIKE4EVER.

  • @stefan429
    @stefan429 3 года назад +1

    finally someone using bytes in network methods xD

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  3 года назад +2

      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.

  • @tomsmith9707
    @tomsmith9707 3 года назад

    Can you make a unity tutorial on volumetric raymarching?

  • @Salmonman0604
    @Salmonman0604 3 года назад

    Definitely gotta do a tutorial on their NetworkList

  • @navinkumar7370
    @navinkumar7370 3 года назад +1

    Shooting mechanism?

    • @DapperDinoCodingTutorials
      @DapperDinoCodingTutorials  3 года назад +1

      I'll definitely be covering shooting/fps mechanics at some point once I've finished covering the basics

  • @Moonz97
    @Moonz97 3 года назад +1

    Thanks! It doesn't seem that hard and actually looks like it's enjoyable to work with.

  • @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?

  • @rucesocial8004
    @rucesocial8004 3 года назад

    Mirror or MLAPI ?

  • @derekdecramer2919
    @derekdecramer2919 3 года назад +1

    Next mirror video when?

  • @DavidZobristGames
    @DavidZobristGames 3 года назад

    liked it first, than watched it

  • @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 года назад +1

      it starts and stops listening to things, it reads in his script's comments

    • @lilbayg9864
      @lilbayg9864 3 года назад

      @@aimojorma7674 thank u alot

  • @SpaceKebab
    @SpaceKebab 2 года назад

    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

  • @rafaeldicker3644
    @rafaeldicker3644 3 года назад

    Can i also change player's movement and it will sync with everyone else?

  • @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 3 года назад

      too much brackets

    • @samochreno
      @samochreno 3 года назад

      cleaner this way

    • @ZiplawDev
      @ZiplawDev 3 года назад

      @@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 3 года назад +1

      @@ZiplawDev i dont really think they are tho, i think its just preference

    • @Mukna132
      @Mukna132 2 года назад

      @@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?

  • @felipeliberado
    @felipeliberado 3 года назад

    can i create a multiplayer 2D game just like a 3D game? With the new unity multiplayer

  • @zakku1653
    @zakku1653 3 года назад +1

    what means subscribing and unsubscribing beacause i dont get this part

  • @cho.gath789
    @cho.gath789 3 года назад +1

    Hey Dapper Dino

  • @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.

  • @mickmickymick6927
    @mickmickymick6927 3 года назад +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