Тёмный

How To Make A Multiplayer Game In Unity - Lobby - Start Game 

Dapper Dino
Подписаться 60 тыс.
Просмотров 53 тыс.
50% 1

Опубликовано:

 

9 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 109   
@nullsomnus
@nullsomnus 2 года назад
I was getting some issues with the spawning of the players, getting an error "OnChangeOwner: Could not find object with netId 1" The fix I found was to add true to the end of the ReplacePlayerForConnection() Before: NetworkServer.ReplacePlayerForConnection(conn, gamePlayerInstance.gameObject); After: NetworkServer.ReplacePlayerForConnection(conn, gamePlayerInstance.gameObject, true); This fixed the issue for me hopefully it can help you
@infokubarcade4510
@infokubarcade4510 4 года назад
Your videos are amazing (yep, i'm commenting because it's the 4th i'm watching in a row :D ), it's kinda fast and entertaining to follow you step by step. I feel like if i was in a classroom and i got a teacher following the project. Very neat and clear videos, i learned and lot without getting bored (which was the biggest obstacle i had about making Multiplayer stuff bc alot of videos are too long or too boring :( ) Continue that way !
@scribl1
@scribl1 4 года назад
In terms of tutorials I'd like to see... So far, I haven't been able to find a single Mirror tutorial or example for a turn-based game. I understand that turn-based should be much easier than real-time games, but the part I'm struggling with is the UI. Like, how do I make it so that each client's UI puts the local client in the main position, and then fills in the other players around the screen? (Most of the UIs I've seen in other Mirror tutorials/samples only display the local client's information.) I'm sure I can get something working through trial and error, I just wish someone would show off some best practices.
@WeidzM
@WeidzM 4 года назад
A way to interact and use UIs in a more scalable and easier way would be ,I agree, not sure if it's just me but I'm kinda lost very fast that way
@PyR0_Dev
@PyR0_Dev 3 года назад
Just a friendly reminder, in the newer versions of unity/mirror, change ALL instances of "SceneManager.GetActiveScene().name" to "SceneManager.GetActiveScene().path" otherwise it will only compare the name of the scene "Scene_Map_01" to the path "assets/scene/Scene_Map_01". and it won't be the same so you'll be stuck in the lobby
@Flynnow
@Flynnow Год назад
Thank you so much for pointing out this problem! I have been struggling with this question for a long time!!!
@turtlemaster890
@turtlemaster890 3 года назад
Can you make a 2d multiplayer? You're the best tutorial-er i've found yet and i can't find any on 2d games.
@MrMrjacky7
@MrMrjacky7 4 года назад
Could you do a tutorial about multiple lobbies management?
@kirbyschmidt6006
@kirbyschmidt6006 4 года назад
Trying to diagnose why the error "RemoveClientAuthority can only be called on the server for spawned objects" is happening. Adding "True" to the ReplacePlayerForConnection(conn, gamePlayerInstance.gameObject, true) means that you are allowing the client to have authority over the previous gameObject (in this case the networkRoomPlayer object). We have already deleted this object so in this case it shouldn't be a problem. But I am not sure.
@bobnacer
@bobnacer 4 года назад
can i ask you? what if i have multiple characters to choose, not just one prefab but many characters prefab, and every player can choose whatever charecter he want, how can we do that?
@whoisgliese
@whoisgliese 3 года назад
you could create prefabs of every character and instantiate them inside the gameplayer game object
@jasgarsoul
@jasgarsoul 3 года назад
@@whoisgliese how?
@whoisgliese
@whoisgliese 3 года назад
@@jasgarsoul so you have a main game object that's gonna be the player, right? except it's just like a placeholder for the actual player, which is going to be another prefab that's gonna change depending on what character you choose. that way you have the same game player prefab and as a child you instantiate the actual character you choose.
@jasgarsoul
@jasgarsoul 3 года назад
@@whoisgliese il try this out in the morning cuz for me its night time right now, i hope it works!
@whoisgliese
@whoisgliese 3 года назад
@@jasgarsoul ay I hope it works for you, I'm glad to help :)
@captainoblivious_yt
@captainoblivious_yt 4 года назад
For some reason, when there are two or more clients in a lobby, the player names switch to "Waiting for player...", but *only* for the one hosting the lobby. It works just like it should for non-host ones. I've no idea how to fix it. Any ideas? I also get errors like "Could not register 'NetworkManager' since it contains no NetworkIdentity component, but when i add a networkidentity component, i get an error saying "Having a networkidentity component is not recommended and will disable the NetworkManager."
@matthewwoodc0
@matthewwoodc0 4 года назад
Same, Have you found a solution yet?
@captainoblivious_yt
@captainoblivious_yt 4 года назад
@@matthewwoodc0 Yes i found a solution that worked for me. I had forgot to disable the Lobby Panel for the RoomPlayer. That solved the "waiting for player" bit. I've still not found a solution to the "Could not register NetworkManager" bit, but it hasn't caused me any direct issues so far so i'm not really all that concerned about it.
@simonvutov651
@simonvutov651 4 года назад
@@captainoblivious_yt I have that problem, is there any solution yet, it isn't causing any direct problems for me either.
@sydneydoc
@sydneydoc 3 года назад
Your videos are great. Do you have anything showing network discovery using Mirror please? Thanks.
@pineappleturnovers9431
@pineappleturnovers9431 4 года назад
Another great and helpful tutorial so thanks! What kind of game are you planning to show us how to make with multiplayer?
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 4 года назад
The game I am making is round based, 2-4 player, last player standing wins (then it goes to the next round and everyone respawns)
@TheStigChristensen
@TheStigChristensen 3 года назад
@@DapperDinoCodingTutorials Nice!
@HoisinDuckWrap
@HoisinDuckWrap 2 года назад
Quick question: If I did this, then played this with my friends, would they need my IP to play?
@adamgallina5155
@adamgallina5155 4 года назад
Why do you loop through the RoomPlayers backwards in your override for ServerChangeScene() in the NetworkManagerLobby?
@stefan429
@stefan429 4 года назад
thanks for pointing that out, mine wasnt working cuz i was doing it the regular way. i guess that answers your question haha
@adamgallina5155
@adamgallina5155 4 года назад
@@stefan429 So it shouldn't make a difference then? Or is there a reason it won't work going the normal way?
@elrondk2712
@elrondk2712 3 года назад
Actually it is important. If we use a "for (int i = 0; i < RoomPlayers.Count; i++)" cycle, then only one player carry over to the new scene, which has index 0, that is, the leader. The other players are transferred to a new scene also, but they end up on some other scene where there are no other players. This can be seen in the inspector - using a "for (int i = 0; i < length; i++)" loop, only one object appears in a new scene. But when we use a "for (int i = RoomPlayers.Count - 1; i >= 0; i--)" loop, we move the players to a new scene from the end and the leader is the last one there. Probably this is important, but I do not understand exactly why yet
@alzahelb6053
@alzahelb6053 3 года назад
Video is kind of old now but if you plan to do any more videos on mirror I would like to see how to manage teams, score, and game loop where it ends the game when 1 of the team wins or maybe after a timer
@nicholasandersen6138
@nicholasandersen6138 4 года назад
Hmm.. My non-host clients seem to not be able to spawn in the players, with an error of "Could not spawn assetId=5b9c7755-cf12-f6e4-7b52-1ea5f37333be scene=0 netId=8" My host gets an "There is already a player for this connection" error. Any idea why?
@jaicarey7023
@jaicarey7023 3 года назад
Hey mate, i had this issue too.. Just figured it out. I had some gameobjects in my menu scene with network identities, that i didnt spawn in. I.E. (I had a little character in the middle of the screen and it had a network identity on it - this is to be used for a skin selection in my game) Because it had a network identity on it and it belonged to no one and the server didnt delete it when the scene changed, I got that error and the server doesnt instantiate the GamePlayer object because its trying to handle the previous error. You need to remove ALL gameobjects with a network identity before changing the scene. That fixed everything for me.
@whoisgliese
@whoisgliese 3 года назад
if you skipped the resources step, that might be it. if you still want to skip it, add the room and game player prefabs to the spawnable prefabs in the network manager.
@FIXXER1001
@FIXXER1001 4 года назад
For someone who pressed the Start butoon but nothing happend, use this in NetworkManagerLobby: public void StartGame() { if (SceneManager.GetActiveScene().path == menuScene) { if (!IsReadyToStart()) { return; } ServerChangeScene("TestScene"); } } public override void ServerChangeScene(string newSceneName) { // From menu to game if (SceneManager.GetActiveScene().path == menuScene && newSceneName.StartsWith("Scene_Map")) { for (int i = RoomPlayers.Count - 1; i >= 0; i--) { var conn = RoomPlayers[i].connectionToClient; var gameplayerInstance = Instantiate(gamePlayerPrefab); gameplayerInstance.SetDisplayName(RoomPlayers[i].DisplayName); NetworkServer.Destroy(conn.identity.gameObject); NetworkServer.ReplacePlayerForConnection(conn, gameplayerInstance.gameObject); } } base.ServerChangeScene(newSceneName); }
@MyRapper34
@MyRapper34 3 года назад
This is worked for me! Thank you so much!!!
@PyR0_Dev
@PyR0_Dev 3 года назад
Thank you so much! I've spent the last week trying to figure it out. after scrolling for awhile I finally found this. if dapper could pin this, I'm sure everyone would appreciate the help when using newer versions.
@yeswanthkumar6652
@yeswanthkumar6652 3 года назад
Thank You! It Works
@flokiololo6698
@flokiololo6698 3 года назад
How to allow players to join the game once it's launched ? When i try to join after the game launched, i have "Client.Send: not connected!". It's a shame for a multiplayer game, i hoped that players could join in game. Thanks in advance !
@liyeon2497
@liyeon2497 3 года назад
Anyone have the solution? I'm having the same problem.
@iangraham6730
@iangraham6730 2 года назад
If anyone solves this, please post it here..
@Keroyz
@Keroyz 2 года назад
has anyone solved it?
@ryanvanderlinden5431
@ryanvanderlinden5431 3 года назад
Hello, awesome tutorial. Perfect for what I'm working on. I'm having an issue where only one player prefab is being created when the game scene is loaded. I've checked to see that the size of the RoomPlayers list is indeed 2 (when 2 players are in lobby) however the for loop only runs once. Does anyone know what I could be missing?
@TheStigChristensen
@TheStigChristensen 3 года назад
I have the same issue. Did you figure it out?
@TheStigChristensen
@TheStigChristensen 3 года назад
I fixed my issue, thanks to this comment: Adam Gallina Why do you loop through the RoomPlayers backwards in your override for ServerChangeScene() in the NetworkManagerLobby? In my ServerChangeScene() I didn't loop backwards.
@ryanvanderlinden5431
@ryanvanderlinden5431 3 года назад
@@TheStigChristensen my fix was to destroy the old player gameobjects only after the for loop runs
@whoisgliese
@whoisgliese 3 года назад
@@TheStigChristensen thanks :)
@FuzzyDPozzy
@FuzzyDPozzy 4 года назад
okay but what's best option for multiplayer photon or mirror? i don't get it.
@DapperDinoCodingTutorials
@DapperDinoCodingTutorials 4 года назад
There is no "best option" different frameworks have different advantages and disadvantages that you'll have to research and compare. In my opinion I prefer Mirror but I can also see why people might want to develop using Photon.
@FuzzyDPozzy
@FuzzyDPozzy 4 года назад
@@DapperDinoCodingTutorials what about having a dedicate server? i mean in photon you would have to pay if you have more than 20 servers so as well buy a dedicated server or a vps?
@Sekunri
@Sekunri 4 года назад
@@FuzzyDPozzy It's not about servers. It's about users connecting to the server. Once you have more than 20 users you have to pay for server space. 20 users not in one game but across all instances of your game. This is why the free version is really only for development purposes so you can test your game with other team members or testers to ensure things are working correctly before expanding. Mirror gives you the option of connecting to a user directly in what is known as Peer to Peer where one of the users acts as the Host for the Remote Clients. While this is definitely more cost effective if the host's internet connection isn't the best then you'll notice a decrease in the quality of gameplay. A dedicated server on the other hand usually suffers less of these issues thus why you're paying a decent amount for them.
@MrJpaulo007
@MrJpaulo007 4 года назад
If you want to support multiple players in multiple rooms, how do you maintain a lobby to receive the clients and then instantiate rooms to players to play in their rooms simultaneous?
@Smokey-A
@Smokey-A 3 года назад
Did you find a solution?
@alexchatziagapis2351
@alexchatziagapis2351 3 года назад
I would love a video of how not to spawn the player on the join lobby. In my game i don't need it for example and after the scene change my player spawns again and loses all hooked info form the previous scene. Don't destroy on load on player will do more bad than good, i guess using the new mirror lobby scripts like tha old unet lobby is the right way but i don't know how to achieve that yet.
@michalber5691
@michalber5691 3 года назад
This light be a bit late but maybe a way to do teams and switch teams?
@adrianalcomendras6754
@adrianalcomendras6754 4 года назад
Hi im getting an error when I go to my game scene MissingReferenceException: The object of type 'NetworkIdentity' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. and the following warnings : Found 'null' entry in spawned list for netId=1. Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy. these go for netId=1 to netId=10 it also keeps outputing the Finished loading scene in host mode. I followed everything on the tutorial to the letter. I dont know why this is happening but it does go to the game scene
@generaljk77
@generaljk77 3 года назад
I'm honestly not sure how I managed it, but somehow my Start Game button is enabled (but does not function) when the host starts a lobby, then fixes itself once either player hits the Ready button. The Start Game button was fine in the prior video (ReadyingUp) so its somewhere in this one. Anyone have any advice?
@potatolegacy
@potatolegacy 3 года назад
i can connect on the localhost *localmachine* but when im using my laptop to connect with the host it wont work how
@rickmasterKKK
@rickmasterKKK 3 года назад
Thank you, helped me a lot
@rabiehaddad1925
@rabiehaddad1925 2 года назад
How to spawn the player its really hard but still good job 😊 you did if show us how to spawn the player
@Fico2501
@Fico2501 3 года назад
I get 2 instances on NetworkGamePlayer in my host window, but in my client window I dont get any NetworkGamePlayer instance. Does anyone know how to fix it?
@jayarammanikumar229
@jayarammanikumar229 4 года назад
can you make a video on auto match making?
@gregdaballah6233
@gregdaballah6233 3 года назад
Is anyone having issues with the client joining the host then instantly getting disconnected? I see "KCP: OnServerConnected(50037)" then immediately after "KCP Connection: Disconnected"
@chaoticdanor
@chaoticdanor 3 года назад
Also having this issue, did you find a fix?
@benedictperalta1049
@benedictperalta1049 3 года назад
I also having this issue
@mikael9931
@mikael9931 4 года назад
So uhh anyone else can't start the game because when host presses ready it just says "Waiting for players..." on both players?? anyone got a fix for this?
@ikee_2947
@ikee_2947 3 года назад
Can i ask a question ? with the use of mirror how can I connect a different or separate computer/android phone? and additional question what if the client is on different network than the server? i'm really having trouble with this one in a month now and regarding on the topic about networking or developing a game in a multiplayer is new to me. i would appreciate if someone can give me some advise/suggestion regarding this problem.
@chaoticdanor
@chaoticdanor 3 года назад
It is all explained in these videos, you connect from multiple devices just by entering the ip address of the host, from the different devices.
@iangraham6730
@iangraham6730 2 года назад
Use your public ip if connecting from outside your LAN, and make sure you forward the port, for the device which you are hosting from in your router. (default port is 7777)
@douglas3445
@douglas3445 4 года назад
This work with two people in diferent city? I don't know english well.
@bryonnicoson2959
@bryonnicoson2959 4 года назад
Douglas, this should work with two people connected to the Internet via use of the IP Address. The host would need to send his IP address to the person who was going to join. For example, he could text his IP address to the joiner.
@olivermoore4794
@olivermoore4794 3 года назад
Will this tutorial work in version 2018.1?
@tobylutz6330
@tobylutz6330 3 года назад
Hey there. I watched your 3 Lobby Tuts. Great! Is it possible to use this for a mobile Game? What is the IP then, for example. Thank you:) Toby
@joshuariefman1984
@joshuariefman1984 3 года назад
IP Addresses are about your wifi network, so it shouldn't matter what platform you're using.
@InfurnusUK
@InfurnusUK 3 года назад
If you're looking at multiplayer with matchmaking for example, you'd need to look into matchmaking servers and possibling renting a server to host it, that way it can have a static IP which can be hard-coded instead of entered by the player
@FastestPodcastClips
@FastestPodcastClips 3 года назад
Is mirror better for massive multiplayer then photon ?
@JOHNSMITH-sj3lg
@JOHNSMITH-sj3lg 3 года назад
mirror is free photon is expensive
@sebastianezequielbalazoteo8882
@sebastianezequielbalazoteo8882 4 года назад
I'm struggling with adding the option Server only besides Host and Client. Main goal being to deploy it to an EC2 instance, I've place the button and the logic being StartServer(), but after the clients join the OnStartClient() lifecycle methods are not being invoked. Anyone tried and experience this?
@ZRoof14
@ZRoof14 4 года назад
Hey Sebastian, I've had some luck by adding in a Start function to the NetworkGamePlayer script private void Start() { DontDestroyOnLoad(gameObject); } It seems like this is a workaround but tbh not sure if this has any downsides yet.
@fv4202x
@fv4202x 2 года назад
minPlayers is wrong. Lower it by 1 to get what you want
@thite2542
@thite2542 3 года назад
can this script use with aws ec2 to create a online game with dedicated server?
@diariodeunindie6119
@diariodeunindie6119 3 года назад
Can someone help me? Everything is fine but when I hit Start Game only the host starts. The clients don't change scene and their connection is timed out after 10000 ms and then disconnect.
@MohammadAli-nk1vn
@MohammadAli-nk1vn 3 года назад
Hi! Did you figure it out? I have the same problem and would love it if you could help me :)
@sagishabon8337
@sagishabon8337 3 года назад
i have problem with this line: gameplayerInstance.SetDisplayName(RoomPlayers[i].DisplayName); on the ServerChangeScene. it showed an error: "InvalidProgramException: Invalid IL code in PlayerSpawnSystem... anyone know how to solve this? pls
@Mrbenjaminbowman
@Mrbenjaminbowman 2 года назад
For anyone having this issue: Update Mirror in the Package Manager
@reggireggie
@reggireggie 3 года назад
For anyone whos having trouble with networkgameplayer spawning only once. I found a solution for the looping problem. public override void ServerChangeScene(string newSceneName) { if(SceneManager.GetActiveScene().path == menuScene && newSceneName.StartsWith("Scene_Map")) { int newNum = RoomPlayers.Count; for (int i = 0; i < newNum; i++) { var conn = RoomPlayers[0].connectionToClient; var gameplayerInstance = Instantiate(gameplayerprefab); gameplayerInstance.SetDisplayName(RoomPlayers[0].DisplayName); NetworkServer.Destroy(conn.identity.gameObject); NetworkServer.ReplacePlayerForConnection(conn, gameplayerInstance.gameObject, true); } } base.ServerChangeScene(newSceneName); }
@elrondk2712
@elrondk2712 3 года назад
or you can use a loop "forr" like this - for (int i = RoomPlayers.Count - 1; i >= 0; i--) {} and then you can use an index "i"
@miguelrubio5215
@miguelrubio5215 Год назад
How you code c# lobby host player??
@nasrighantous4435
@nasrighantous4435 4 года назад
I suggest being a 2d platformer with shooting and stuff
@TheStigChristensen
@TheStigChristensen 3 года назад
I would love that!
@haseebzhd
@haseebzhd 2 года назад
source code ?
@sneakycheeky531
@sneakycheeky531 4 года назад
@letisschiller5185
@letisschiller5185 4 года назад
And again every "GetActiveScene.name" change it to "GetActiveScene.path"
@Sekunri
@Sekunri 4 года назад
Alternatively, for anyone else reading this, if this still gives you problems for some reason (I am still having issues getting either path or name to work) then you can take the approach of just writing the name out. Remove [Scene] and write it out as follows. [SerializeField] private string menuScene = string.Empty; Now just change the scene name in the inspector but make sure it perfectly matches the way the scene's name is written. Capitals and spaces where they are needed.
@Manofthebean
@Manofthebean Год назад
you keep deleting stuff out of the video it is so annoying you. please can you not delete things in a tutorial that is this long
@osmanaktas77
@osmanaktas77 4 года назад
Photon is easy and stable more than shitty way
@chaoticdanor
@chaoticdanor 3 года назад
But Photon is not free :)
@Kaasbroodje30
@Kaasbroodje30 Год назад
Assets\Tutorials\Lobby\Scripts\NetworkManagerLobby.cs(50,30): error CS0115: 'NetworkManagerLobby.OnClientConnect(NetworkConnection)': no suitable method found to override Assets\Tutorials\Lobby\Scripts\NetworkManagerLobby.cs(57,30): error CS0115: 'NetworkManagerLobby.OnClientDisconnect(NetworkConnection)': no suitable method found to override Assets\Tutorials\Lobby\Scripts\NetworkManagerLobby.cs(64,30): error CS0115: 'NetworkManagerLobby.OnServerConnect(NetworkConnection)': no suitable method found to override Assets\Tutorials\Lobby\Scripts\NetworkManagerLobby.cs(79,30): error CS0115: 'NetworkManagerLobby.OnServerAddPlayer(NetworkConnection)': no suitable method found to override Assets\Tutorials\Lobby\Scripts\NetworkManagerLobby.cs(93,30): error CS0115: 'NetworkManagerLobby.OnServerDisconnect(NetworkConnection)': no suitable method found to override Assets\Tutorials\Lobby\Scripts\NetworkManagerLobby.cs(179,30): error CS0115: 'NetworkManagerLobby.OnServerReady(NetworkConnection)': no suitable method found to override Anyone help?
@whitehawk9571
@whitehawk9571 Год назад
Can you check if NetworkManagerLobby is inheriting from NetworkManager? At the top it should say "public class NetworkManagerLobby : NetworkManager"
Далее
Get Started With Unity - Tweening Animation
16:15
Просмотров 11 тыс.
🤔Угадай постройку | WICSUR #shorts
00:59
Katta janjal
00:29
Просмотров 231 тыс.
HOW TO MAKE YOUR FIRST GAME!
11:17
Просмотров 157
How to Build a Multiplayer Game with Unity + Mirror
26:30
Wizards In Training - Behind The Scenes - Basic Combat
15:38