- Home /
Question by
Bazsee125 · Mar 07, 2018 at 09:16 PM ·
multiplayermultiplayer-networkingthreadsthreadingthread
LobbyHook doesn't give clients variables
Related code from the hook:
public class MyLobbyHook : LobbyHook {
public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager,
GameObject lobbyPlayer, GameObject gamePlayer)
{
LobbyPlayer lPlayer = lobbyPlayer.GetComponent<LobbyPlayer>();
NetPlayer gPlayer = gamePlayer.GetComponent<NetPlayer>();
gPlayer.playerName = lPlayer.playerName;
gPlayer.color = lPlayer.playerColor;
gPlayer.respawnTime = FindObjectsOfType<LobbyPlayer>().Length < 2 ? 1 : 1.17f * FindObjectsOfType<LobbyPlayer>().Length - 1.33f;
}
from the player:
public class NetPlayer : NetworkBehaviour {
[SyncVar (hook ="OnNameChanged")]
public string playerName;
[SyncVar(hook ="OnColorChanged")]
public Color color;
private void OnNameChanged(string value)
{
playerName = value;
gameObject.name = value;
showName.text = value;
}
void OnColorChanged(Color value)
{
GetComponentInChildren<SpriteRenderer>().color = value;
}
So, unless I attach to Unity in VS15, breakpoint at the OnLobbyServerSceneLoadedForPlayer and F11 a bunch, the clients have all players with default color and name.
This seems to happen because of threading issues, the client loads in faster, then it could get the dat from the server. Is there any way to make sure the hook gets called before the client is fully loaded in?
Comment