Sync Chosen Hero in Character Selection Screen Between 6 Players in Room

Options
Hi everyone, I am stuck at the moment on how to sync Chosen Hero in Character Selection Scene between 6 players. It's an arena brawler game and those 6 players are divided equally 3 players in Team Red and 3 players in Team Blue. Each player cannot use the same hero. I could think of passing a string indicating chosen hero name from each player but I don't know how to pass that string to each player in the room. What is the best way to do this?

Thank you for your help and reply

Comments

  • Hi @ActiveDream,

    there are different options how you can achieve this. The first one is to add the name of the Hero to the client's Custom Player Properties. This can be done by using PhotonNetwork.LocalPlayer.SetCustomProperties. These properties are automatically synchronized on all clients, which means that other clients can access a certain client's chosen hero.

    Another option would be using the Custom Room Properties. They work similar as the Custom Player Properties, but they are related to the room. To set them, a client can use PhotonNetwork.CurrentRoom.SetCustomProperties. Here you could store a pair containing the player name or his actor number (this is unique) and his chosen hero.

    Since the chosen hero is related to the player, I would personally go with the first option.

    You have mentioned, that each hero can only be selected once, which would require some more work to implement. In this case I would raise an event next to updating my Custom Player Properties. So whenever a clients selects a hero, he updates his properties and raises an event with the name or ID of the selected hero. When a client receives this event, his game logic has to disable the possibility to select this certain hero. When a client, who already has selected a hero, selects another one, he has to tell the other clients, that his previous hero is free to select again. Please note: it is very hard or even impossible without server-side logic to prevent two clients from selecting the same hero at the exact same time.