Trouble Getting NetworkLobby to update player names on Client
I'm using the NetworkLobby from the asset store. I'm attempting to take the form input (player name) and update the gameplayer using the associated lobbyplayer object. Per various tutorials and samples, the magic place for that to happen is apparently in the OnLobbyServerSceneLoadedForPlayer() method. I have the following code running on the Lobby Manager.
public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer) {
LobbyPlayer lPlayer = lobbyPlayer.GetComponent<LobbyPlayer>();
Player gPlayer = gamePlayer.GetComponent<Player>();
gPlayer.playerName = lPlayer.playerName;
}
}
So far so good. The Player object has a synvar with a hook...
[SyncVar(hook = "OnNameChanged")] public string playerName;
And the hook looks like this:
void OnNameChanged(string value) {
playerName = value;
gameObject.name = "Player (" + playerName + ")";
if (GetComponentInChildren<Text>(true) != null) {
GetComponentInChildren<Text>(true).text = playerName;
}
}
When I run this, from the server's perspective, everything goes as it should. All the players get named correctly and their Text object gets set. From the client's perspective, player name never gets set for any player. What am I missing?
Any help would be very much appreciated, I've been struggling with this for a while.
Can you run the build as the server and then run the editor as a client and use the inspector to deter$$anonymous$$e if the value is being set at all? Perhaps it just cannot find the text component to visually update it but the variable is still receiving its value. Otherwise, you may need to use break points to follow the full flow of logic from the lobby hook to the name change hook
Value not getting set at all by client. The more i test this, the more erratic it appears to be. I believe it has something to do with my player object prefab taking a bit to load (using uma). What's odd about it is the player lobby seems willing to move on to the scene with the client player object not fully loaded.
What's uma? Also, delayed loading shouldn't matter. SyncVars are updated as soon as the object manages to load in. Can you submit a stripped down version of your project (just the bits that you can share / show the error) as a bug and send me the case number?
Your answer
Follow this Question
Related Questions
Best Practice for an object that is both online and offline using uNET 0 Answers
Network Player Direction in Unity 0 Answers
How can I send update to all clients from one client in Multiplayer game in Unity3d? 0 Answers
How can I continuously receive the location of game object from 000webhost database? 0 Answers
[UNET] Cant get player to parent with boat and sync position 1 Answer