How to set Player Custom Properties in Photon fusion?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on Fusion.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
How to set Player Custom Properties in Photon fusion?
princeladdi
2022-09-01 10:52:30
I have used PUN2 previously for making multiplayer turn based games . It has a method for storing local player's custom data which can be read by other players in the room.
Now I am trying to do same using Photon fusion but can't find a way to get around it?
Does anyone have any Ideas or alternate solution around it?
Comments
While Custom Properties in PUN were Hashtables with setter methods, Fusion synchronizes plain C# properties instead: As part of a NetworkBehaviour
, auto-implemented properties just need a [Networked]
attribute to become part of the game state.
So you write a NetworkBehaviour and use it per player. The players can send an RPC to set the values, which need to be set by the host/server.
princeladdi
2022-09-01 12:34:34
So , What I get from this is that whenever any player joins a session, it calls an RPC to every other client with its properties set as a parameter to that RPC method and everyone gets the user data of that connected client ?
Am I getting it right?
Almost right.
The client send the RPC to the host/server and this sets networked properties on a NetworkBehaviour-instance, which is for this player.
Then those values become available to the other players.
How would you recommend going about setting player properties that can be used for matchmaking?
We are using Shared mode. Players Join the lobby and then search through the session list in the OnSessionListUpdated callback. So we need to know some data about the player before their Player instance (which inherits from NetworkBehaviour) is instantiated after joining a session.
Our use case is we have a game that has two character types on different teams. The player chooses which character type in the front end, and there can be up to three players on each team.
Ideally we would have a way to find player custom data in the OnPlayerJoined callback so that the session properties for how many members are on each team can be updated immediately. Currently the delay between a player joining, them instantiating their own Player instance and syncing the team id using the [Networked] attribute is enough for other players to join the session for the same team, even though that team is already full and we have to kick them.
In short we are looking to implement some form of Team Matchmaking. Thank you.
Just a bump of my last question a couple months ago above?
Hi @Amuzo maybe the answer is here: https://doc.photonengine.com/fusion/current/manual/matchmaking
Thanks @Pesseba,
Unfortunately the issue is more the delay after a runner joining the session with a PlayerRef and instantiating the game object that can hold the NetworkBehaviour that @Tobias mentions with [Networked] attributes that are synced over network and so able to update session properties about how many players on on each team.
It can be enough time for another player to join for the same team.
So if there was a way to get information about the team the player has chosen at the point of joining the session, say in the PlayerRef for instance it would prevent this, or at least reduce it.
Back to top