#Session Player Properties
1 messages · Page 1 of 1 (latest)
Youve got it backwards in the session options here. It would be new("name",playerProperty) That will set the hosts player name. The other player could do the same with JoinSessionOptions
If you want to change them after joining then you would use
session.CurrentPlayer.SetProperty("name", new("[changed name]", VisibilityPropertyOptions.Public)); session.SaveCurrentPlayerDataAsync();
There are events you can listen for when player properties change. The docs a bit light but it just when 1.0 release a few days ago. Hopefully in the next month with Unity 6 releasing they will give the docs another pass
so, like this?
I don't really get it
:ccc
public async void CreateRoom()
{
// Check if player is in a lobby already, if so quit it
RoomFound = false;
try
{
PlayerProperty playerName = new("PlayerName", VisibilityPropertyOptions.Public);
var options = new SessionOptions
{
PlayerProperties = new("_playerName", playerName),
MaxPlayers = 2
}.WithRelayNetwork();
var session = await MultiplayerService.Instance.CreateSessionAsync(options);
session.CurrentPlayer.SetProperty(AuthenticationManager.Instance.PlayerName(), playerName);
RoomFound = true;
_hostNameText.text = SecurePlayerPrefs.GetString("_displayName", "");
_lobbyRoomCodeText.text = session.Code;
}
catch (SessionException e)
{
Debug.Log(e);
}
}```
Yea. But you only need to set the property once. Either in the Sessions options or after you connect with setProperty()
oh
so this
so the green stays?
but then, when joining the lobby, "playerName (PlayerProperty)" is not existent
so it would be a variable like this, outside my function?
and then calling it like this?
JoinRoom()
is this correct?
public async void CreateRoom()
{
// Check if player is in a lobby already, if so quit it
RoomFound = false;
try
{
var options = new SessionOptions
{
MaxPlayers = 2
}.WithRelayNetwork();
var session = await MultiplayerService.Instance.CreateSessionAsync(options);
session.CurrentPlayer.SetProperty(AuthenticationManager.Instance.PlayerName(), _playerName);
RoomFound = true;
_hostNameText.text = SecurePlayerPrefs.GetString("_displayName", "");
_lobbyRoomCodeText.text = session.Code;
}
catch (SessionException e)
{
Debug.Log(e);
}
}
public async void JoinRoom(string roomCode)
{
Debug.Log($"Is room found already?: {RoomFound}");
RoomFound = false;
try
{
var session = await MultiplayerService.Instance.JoinSessionByCodeAsync(roomCode);
session.CurrentPlayer.SetProperty(AuthenticationManager.Instance.PlayerName(), _playerName);
_guestNameText.text = AuthenticationManager.Instance.PlayerName();
RoomFound = true;
_lobbyRoomCodeText.text = session.Code;
}
catch (SessionException e)
{
Debug.Log(e);
}
}```
The first parameter of SetProperty() is the key string. so it will be "PlayerName" or whatever. the second part will be the PlayerProperty that contains the actual user name
oh
so, I would have to... hmm
it would be like this?
session.CurrentPlayer.SetProperty("PlayerName", new("-Player name here-", Public));```
like this?
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));```
Right, either of those will work. the visibility is Public by default.
right. saving it basically will upload the data to the session so other players can see it
oh, cool!
and now
XD
to get it?
session.Host.GetProperty("PlayerName"); XD?
that doesn't exist :'v
no, session.Players is a list of all players.
You can loop through them and get player.Properties["PlayerName"] for each player
There is also a session.PlayerPropertiesChanged that you can subscribe to get when ever a player property has changed.
that change _hostnameText to the last player that joined
if you only have 2 player then that will be fine
I will implement spectating later on but
for now that would work I guess
hmm what would be to get the property value?
I think I got it
it works for the Guest
but the host still doesn't have the Guest name when they're joining hmm 😦
this is such a mess, and it's just the lobby
I haven't even gotten to the gameplay part xDDDDDDDD
The host need to sub to the Player joined event as well