Custom properties are not saved over different scenes
Options
I got a tricky problem. In my MainMenu-scene I want to split up the players in two teams, what already works. In this method, the custom property "Teamnr" of every player will be set . If I log the custom property in the same method it works. Unfornately, it doesn't work to get the custom property from the MainMenu-scene in the new scene to show a different view. Does anybody know how to fix this? Here are my both methods:
The SetTeam-method: https://ibb.co/vwZ7dFt
The SetMenu-method by getting the properties of SetTeam: https://ibb.co/F3xmgp4
If you have any questions, please ask me. I'm thankful for every help I get because I'm not working with PUN2 a long time.
The SetTeam-method: https://ibb.co/vwZ7dFt
The SetMenu-method by getting the properties of SetTeam: https://ibb.co/F3xmgp4
If you have any questions, please ask me. I'm thankful for every help I get because I'm not working with PUN2 a long time.
0
Comments
-
The Custom Properties are stores in a Room or per Player. This is independent from the scene, so by all means, the values should not change due to changing scenes (unless you also change the room or set properties).0
-
But now I got another problem. The MasterClient says via RPC that a special menu will be enabled for all players - what already works. At every player's screen a text should be set, which tells him to which team he belongs. It works on the MasterClient, but not on the another clients. The clients get a null pointer exception at "string team = playerInfo.CustomProperties["Teamnr"].ToString();" Does anybody know what the problem is? It looks like the custom properties are deleted after the masterClient read it. PS.: Setting the team number for every player's custom properties is already working.
//If Button clicked
public void OnClick_StartGame()
{
if (PhotonNetwork.IsMasterClient)
{
if(PhotonNetwork.CurrentRoom.PlayerCount != PhotonNetwork.CurrentRoom.MaxPlayers)
{
info.text = "Not enough Players to start";
return;
}
info.text = "";
PhotonNetwork.CurrentRoom.IsOpen = false;
PhotonNetwork.CurrentRoom.IsVisible = false;
setTeam = new SetTeam();
setTeam.SetPlayerToTeam();
base.photonView.RPC("EnableAbilityMenu", RpcTarget.All, true);
}
}
[PunRPC]
private void EnableAbilityMenu(bool b)
{
if(b == true)
{
//This is working for all Clients
createOrJoinRoomMenu.SetActive(false);
currentRoomCanvasMenu.SetActive(false);
abilityMenu.SetActive(true);
//This is working only at masterClient
foreach (var playerInfo in PhotonNetwork.PlayerList)
{
string team = playerInfo.CustomProperties["Teamnr"].ToString(); //Here appears the null
reference exception at the clients
if (team.Equals("1"))
{
abilityMenuSubheading.text = "You're in Team: Attacking";
}
else
{
abilityMenuSubheading.text = "You're in Team: Defending";
}
}
}
}
0