Ok I'm new to Playfab and am really struggling to get two players spawned into a room in Unity. I have a matchmaking system with tickets working, and everything up to GetMatch works GREAT. Thing is, I can't find any documentation online or instructions on what to do after GetMatch to get the players spawned in a room.
I have a custom Network Manager where I want to add player prefabs to a scene, and have those prefabs be moveable and have that movement represented on all clients - so I know the two are in the same room and connected. Thing is, I have no idea what to do. I'm assuming OnServerAddPlayer(NetworkConnection conn) is the function we override and is where we spawn the players locally & on server, but I've had no luck with calling it.
I'm trying to run the unity debugger on the client side to stop when OnServerAddPlayer is run, but it's never triggered. Maybe it only runs on the server-side and we never see it? I have no way of knowing if it's actually being triggered. Here's my code for that function:
public override void OnServerAddPlayer(NetworkConnection conn) { // add player at correct spawn position Transform start = numPlayers == 0 ? pos1 : pos2; GameObject player = Instantiate(playerPrefab, start.position, start.rotation); player.name = $"Player({numPlayers})"; NetworkServer.AddPlayerForConnection(conn, player); spawner.CmdSpawnPlayer(); }
My intention is to spawn the player, and tell the server to spawn the player prefab. I haven't had any luck, so I assumed that I needed to maybe get the player to tell the server to spawn the object (hence CmdSpawnPlayer).
The player prefabs have network identities and NetworkTransforms on them and do not have the server checkbox ticked.
I've also noticed that ClientScene is adding players, and looking at the comments above it, it says that NetworkManager.OnServerAddPlayer should be the next thing called. Again - idk if it's actually calling it, because it's not breakpointing on my client, and I'm not seeing anything from the server.
I'm kinda just trying a shotgun approach and hoping something makes the player prefab appear because I have a real hard time reading documentation and nobody I can find has footage on what to do with the GetMatch data to spawn players. I'm so stuck because nobody else is doing exactly what I'm doing - DapperDino has a Youtube video on everything up to this step following GetMatch, so AFAIK nobody has a good explanation as to the exact steps we do after Matchmaking is complete and the match is got.
Can somebody help me out?