I'm new to multiplayer and photon so pardon me if this question is somewhat frequent.

I have successfully set up my project to start from a main menu - waiting room - actual gameplay scene. However I couldn't search my way through getting a sort of user id from waiting room(ie; order of user joined to waiting room) then use it in the gameplay scene to manipulate sort by score / by hp / etc.

Perhaps I got the while concept of having to identify unique players via such variable? I'm not quite sure. I just got my foot in the multiplayer development realm, so please go easy on me.

// Edit

enter image description here

Sorry for my initial question being quite vague. Basically, I'm trying to replicate this with Photon. I've got various things set up but was stuck at where designating individual players to individual player info panels as if captured(Get WHAT to connect to those UI elements I've got set up).

It'd be simple enough even for me if this was a singleplayer, but since it's not I'm also refactoring a lot on the way as well. Thanks to both of the answers given so far I'm looking into Photon UtilityScripts(To a novice to anything simply directing where to look helps a ton, so thanks again), but since I'm not quite there yet I'll update my progress.

  • 2
    \$\begingroup\$ Are you perhaps looking for What is the proper way to handle data between scenes? \$\endgroup\$
    – DMGregory
    Feb 6, 2020 at 13:01
  • \$\begingroup\$ Please don't redact a question if it ends up missing the focus you intended. It might still be useful to other users, even if it's not quite what you need. Consider instead editing this question to focus on the issue addressed by the current answers. Then you can still post a new question with your refined focus. \$\endgroup\$
    – DMGregory
    Mar 21, 2020 at 23:42
  • \$\begingroup\$ @DMGregory I won't. I'll keep this post alive as is. Thanks for the heads up. \$\endgroup\$ Mar 21, 2020 at 23:43

2 Answers 2


If you're using Photon, you should be able to set each user id in one of the following ways:

Once authenticated, a Photon client will keep the same UserID until disconnected. The UserID for a client can be set in three ways:

  1. Client sends its UserID before connecting by setting AuthenticationValues.UserId. This option is useful when you do not use Custom Authentication and want to set a UserID.
  2. An external authentication provider returns the UserID on successful authentication. See Custom Authentication. It will override any value sent by the client.
  3. Photon Server will assign GUIDs as IDs for users that did not get UserIDs using 1 or 2. So even anonymous users will have UserIDs.

So basically, if you don't set it, it will set a userID for you.

You can then get the userID for each player to be published to each player in the room by setting RoomOptions.PublishUserID = true, and finally getting the UserId with PhotonPlayer.UserId

Players can share their UserIDs with each other inside rooms. To enable this and make the UserID visible to everyone, set RoomOptions.PublishUserId to true, when you create a room. The server will then broadcast this information on each new join and you can access each player's UserID using PhotonPlayer.UserId.

Then using it across different scenes, you will want to store it in a script Component on a GameObject and use DontDestroyOnLoad(this.gameObject) in the Start() function for this script. This will cause the script to stick around between scenes. (Be careful with this though, you could end up with multiples, so make sure it's only created once) See the docs for DontDestoryOnLoad here: https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

See the full detail here: https://doc.photonengine.com/en-us/pun/current/lobby-and-matchmaking/userids-and-friends


If you want to keep track of the order when users joined the room (which should actually not matter much) you just need to keep track of them when they join the room. Photon is providing the player with OnPhotonPlayerConnected(PhotonPlayer newPlayer). You can set the time when they joined the room in the custom room property if needed with a time stamp. Let the masterclient handle it or let each client write it when they arrive. If you want to get a whole list of them at once, you can access them via PhotonNetwork.playerList.

PhotonNetwork persists between scenes and there are a few example tutorials provided directly by Photon. It's worth checking out both Pun and Pun2, since the examples they have are slightly different (Pun has for example a simple Rock-Paper-Scissor game which is missing in Pun2) but the code is almost the same.

And if you want to use something for displaying as scores, you should not use the userId but instead PhotonNetwork.player.NickName. The userId is unique, the Nickname is usually what the player is itself choosing and does not need to be unique.

I assume your game is round based (looks like auto chess or similar). Each player could just report his own stats after each round with PhotonNetwork.RaiseEvent(TOKEN_UPDATE_SCORE, payload, true, new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache });. You need to subscribe to PhotonNetwork.OnEventCall += OnEvent; where public void OnEvent(byte eventCode, object content, int senderId). All clients are getting that way an update of the score after each round (or whenever you call it)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .