Photon PUN Integration

Photon PUN (Photon Unity Networking) is one of the most popular Unity multiplayer solutions. Universal Friend List supports both PUN's native friends system and the custom ElderWorldStudio server for enhanced features.

Prerequisites

Photon PUN 2 Requirements

  • Photon PUN 2 package installed (from Asset Store or Photon's website)
  • A Photon App ID configured in the PhotonServerSettings asset
  • Unity 2021.3 or newer

To get started with Photon PUN:

  1. Download Photon PUN 2 from the Unity Asset Store
  2. Import the package into your project
  3. Unity will prompt you to create/set a Photon App ID
  4. Follow the setup wizard to configure your App ID (free tier available)

Option 1: Native PUN Friends (Simplest)

Uses Photon's built-in friends system. This is the fastest setup but is limited to Photon-only friends.

Configuration

  1. Open your scene with FriendManager or add the FriendManagerInitializer
  2. Select the initializer and in the Inspector:
    • Set Settings to your FriendManagerSettings asset
    • Set Backend Type to PhotonPUN
    • Set Use Native Implementation to true
  3. Set Initialize On Start based on your game flow

How It Works

  • User ID is automatically taken from Photon's PhotonNetwork.AuthValues.UserId
  • Friend operations use Photon's PhotonNetwork.FindFriends() and related methods
  • Presence (online/offline status) comes from Photon's room and player properties
  • No additional server required

Limitations

  • Friends are Photon-specific (other users must also use Photon)
  • Limited moderation features
  • No cross-platform friends

Option 2: Custom Server with PUN

Uses the included Node.js or PHP server for friend management while still using Photon for game networking. This gives you server-side moderation and consistent friends across platforms.

Configuration

  1. Set up your server (see Server Setup)
  2. Open FriendManagerSettings and configure:
    • Set Backend Type to PhotonPUN
    • Set Use Native Implementation to false
    • Set Use WebSocket to true (recommended) or false
    • Set ServerUrl to your server address
    • Set WebSocketUrl to your WebSocket address

User ID Mapping

When using custom server with PUN, you need to map Photon user IDs to your server's user IDs:

  • Photon provides PhotonNetwork.AuthValues.UserId
  • This UserId is sent to the custom server for authentication
  • Your server can store additional metadata linked to this ID

Example: Custom PUN Connection

See Scripts/Examples/NetworkConnections/SimplePun2Connection.cs for a complete example:

using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

public class SimplePun2Connection : MonoBehaviourPunCallbacks
{
    public void ConnectToPhoton() {
        PhotonNetwork.AuthValues = new AuthenticationValues();
        PhotonNetwork.AuthValues.UserId = "my_user_id";
        PhotonNetwork.ConnectUsingSettings();
    }

    public override void OnConnectedToMaster() {
        Debug.Log("Connected to Photon Master");
        // Now you can use FriendManager
        // The UserId from Photon.AuthValues will be used
    }
}

Troubleshooting

IssueSolution
Friend list always emptyCheck Photon App ID is configured correctly
Friends not appearingOther players must be connected to same Photon region
Native implementation not workingEnsure UseNativeImplementation = true in settings
Custom server connection failsVerify ServerUrl and WebSocketUrl in settings