UserIDs and Friends


In Photon, a player is identified using a unique UserID.

This UserID is useful inside and outside rooms. Photon clients with the same UserID can be connected to the same server but you can't join the same Photon room from two separate clients using the same UserID. Each actor inside the room should have a unique UserID. In old client SDKs, this was enabled using RoomOptions.CheckUserOnJoin.

Unique UserIDs

Generally, UserIDs are not intended to be displayed. Unlike usernames, displaynames or nicknames. A UserID does not have to be human-readable or very human-friendly. So you could, for instance, use a GUID as a UserID.

The advantages of keeping a unique UserID per player:

  • You preserve your data between game sessions and across multiple devices. You can rejoin rooms and resume playing where you stopped.
  • You can become known to all players you meet and easily identifiable by everyone. You can play with your friends, send them invitations and challenges, make online parties, form teams and guilds, etc. You can add user profiles (e.g. experience, statistics, achievements, levels, etc.) and make games more challenging (also using tournaments and leaderboards).
  • You could make use of another service to bind Photon UserID to an external unique identifier. For instance, Photon UserID could be set to Facebook ID, Google ID, Steam ID, PlayFab ID, etc.
  • You can prohibit malicious users from connecting to your applications by keeping a blacklist of their UserIDs and making use of Custom Authentication.

Setting UserIDs

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.

Publish UserIDs

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.


Only friends connected to the same AppID, the same Photon Cloud region and play the same Photon AppVersion can find each other no matter what device or platform they're using.

You can find out if your friends who are playing the same game are online and if so, which room they are joined to. Like users, friends are also identified using their UserID. So the FriendID is the same thing as the UserID and in order to find some friends you need to know their UserIDs first. Then you can send the list of UserIDs to Photon Servers using:


You can then get the response sent from the server as follows:

If you are extending LoadBalancingClient class then override OnOperationResponse and add the following code snippet. You could also make use of the event LoadBalancingClient.OnOpResponseAction and add the following snippet to the implemented callback instead.

    case OperationCode.FindFriends:
        if (operationResponse.ReturnCode == 0)
            bool[] statusArray = operationResponse[ParameterCode.FindFriendsResponseOnlineList] as bool[];
            string[] roomsArray = operationResponse[ParameterCode.FindFriendsResponseRoomIdList] as string[];

            for (int index = 0; index < this.FriendList.Count; index++)
                // replace with your custom logic
                Debug.LogFormat("Friend with UserId={0} is {1}{2}", 
                    statusArray[i] ? "online" : "offline", 
                    string.IsNullOrEmpty(roomsArray[i]) ? string.Empty : 
                    string.Format(" joined to room=\"{0}\"", roomsArray[i]));

Photon does not persist friends lists. You may need an external service for that.

Since Photon does not keep track of your userbase, any non existing user in your game will just be considered offline. A friend is considered online only when he/she is connected to Photon at the time of making the FindFriends query. A room name will be returned per user if the latter is online and joined to the room with the same name.

 To Document Top