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
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 !
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.
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
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.
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?
@@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.
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 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.
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
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
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?
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.
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.
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); }
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.
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 !
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?
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.
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.
@@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?
@@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.
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?
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.
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
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?
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?
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"
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?
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.
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)
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.
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
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?
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.
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.
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
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); }
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.
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?