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:
- Download Photon PUN 2 from the Unity Asset Store
- Import the package into your project
- Unity will prompt you to create/set a Photon App ID
- 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
- Open your scene with FriendManager or add the FriendManagerInitializer
- Select the initializer and in the Inspector:
- Set Settings to your FriendManagerSettings asset
- Set Backend Type to
PhotonPUN - Set Use Native Implementation to
true
- 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
- Set up your server (see Server Setup)
- Open FriendManagerSettings and configure:
- Set Backend Type to
PhotonPUN - Set Use Native Implementation to
false - Set Use WebSocket to
true(recommended) orfalse - Set ServerUrl to your server address
- Set WebSocketUrl to your WebSocket address
- Set Backend Type to
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
| Issue | Solution |
|---|---|
| Friend list always empty | Check Photon App ID is configured correctly |
| Friends not appearing | Other players must be connected to same Photon region |
| Native implementation not working | Ensure UseNativeImplementation = true in settings |
| Custom server connection fails | Verify ServerUrl and WebSocketUrl in settings |