Hi!
This is going to be a long post so I would appreciate if you could help me out with this..
So far I was able to create a lobby, get the steam ID of players who join and see them listed.
The host can then start the game and the player prefabs are able to spawn.
Here is the problem:
Every Client except the Host get their Names mixed up..
Example:
Lobby:
Player 1 (host)
Player 2
Player 3
Player 4
and once I start the game, it gets randomly assigned (except the host)
Player 1 (stays always the same)
Player 2 is now called Player 4
Player 4 is now called Player 3
Player 3 is now called Player 2
It’s completely random, I tried it couple a times, sometimes everyone gets their name correct.
The good thing is, I think I know what part of my code handles that, but I can't get it to work...
I have been trying to fix this issue for like 4 days straight..
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
{
base.OnServerAddPlayer(conn);
MyNetworkPlayer player = conn.identity.GetComponent<MyNetworkPlayer>();
Players.Add(player);
CSteamID steamId = SteamMatchmaking.GetLobbyMemberByIndex(
Menu.LobbyId,
numPlayers - 1);
var playerInfoDisplay = conn.identity.GetComponent<MyNetworkPlayer>();
playerInfoDisplay.SetSteamId(steamId.m_SteamID);
// for (int i = 0; i < Players.Count; i++)
// {
// player.SetPlayerName("Player " + i);
// }
player.SetPartyOwner(Players.Count == 1);
}
If you need any more code snippets, please let me know
Thank you in advance