Skip to main content
This section provides info about using PlayFab together with Photon multiplayer services such as Photon RealTime and Photon Unity Networking (PUN). Currently, we offer the following Photon integrations:
  • Authenticate Photon players with PlayFab.
  • Listen for room events using PlayFab CloudScript callbacks.

Photon quickstart

This quickstart shows how to set up Photon Multiplayer to work with PlayFab. Currently, PlayFab offers the following Photon integrations:
  • Authenticate Photon players with PlayFab.
  • Listen for room events using PlayFab CloudScript callbacks.
In this quickstart, we illustrate how both features work using the latest Photon Unity example project.
For a fully supported PlayFab Multiplayer and Chat Experience on Unity, see the PlayFab Party Unity Plugin for more information.

Prerequisites

  1. A Unity project with the PlayFab SDK imported, and a configured title.
  2. The PlayFab title registered.
This guide omits the Chat Application settings. For your Chat Application to be integrated, create a new Photon Chat Application, and enter the App ID in the corresponding boxes in Unity and in the PlayFab Game Manager - Photon Add-on page.

Setting up a Photon application

  1. Once you have registered and logged into the Photon dashboard, select Create a new App.
  1. Select Photon Type.
  2. Choose a Name.
  3. Create a Description.
  4. Submit by selecting Create.

Setting up authentication

  1. Find the newly created Application in the list, and select Manage.
  1. In the Application dashboard, find and save the App ID located under the page Title.
  1. Locate the Authentication section.
  2. Select the Custom Server.
The next page lets you configure the Authentication URL for Photon.
Replace the PlayFabTitleId place holder with your own Title Id.
  1. Enter the URL.
  2. Submit by selecting the Create button.

Setting up a PlayFab title for Photon

Navigate to your title’s Game Manager page, then:
  1. Navigate to Add-ons tab.
  2. In the list of Add-ons, find and select Photon.
  1. The Photon Add-on page allows you to install Photon by specifying your Photon Realtime Application ID.
    • Optionally, you may specify Chat App ID.
    • Once you install the Add-on (3), a Photon secret Key is generated (2).
    • Save it for future use when configuring web-hooks.
Remember to save your Photon secret key in a safe and easily accessible place. It comes in handy when configuring Webhooks.

Setting Photon webhooks

As an optional integration, Photon may transmit certain events to your PlayFab CloudScript. This is done with webhooks:
  • You specify a Base URL.
  • Then you specify path for each of the available Events.
  • A path is, effectively, a handler name implemented in your CloudScript.
The base URL has the following format:
Make sure to replace Title Id placeholder with your own Title Id.
Make sure to replace the PhotonSecretKey token with the Secret Key you generated on the Photon Add-on page.
  1. Fill in the Base URL.
  2. Assign a CloudScript handler Name for each of the available Events.
  3. Remove any CustomHttpHeaders.
  4. Submit this by selecting the Save button.

Setting up a Unity project

The guide assumes you already have PlayFab SDK imported, set up, and the title setting configured. Right after import process finishes, the PUN Setup window opens.
  • Enter your Realtime Application ID (1) found in the Photon Application Dashboard for the Photon App you created.
  • Select Setup Project (2).
  • Once the setup finishes, select Close (3).
If AppId was accepted, the Photon Server Settings object is selected and viewable in the Unity Inspector window. To manually access the Server Settings object:
  • Navigate to the top window panel.
  • Select Window.
  • Then select Photon Unity Networking (1).
  • Finally select Highlight Server Settings (2).
  • The Standard Unity project window reveals the PhotonServerSettings (3) object.
  • Select the object to reveal its settings in the Unity Inspector window.
As part of PhotonServerSettings, you have the option to assign the Chat Application ID.
At this point, the project is configured.

Implementing PlayFab to Photon authentication

When you enable the Photon Add-on for your title in the PlayFab Game Manager, and configure the authentication on the Photon Application dashboard, PlayFab allows you to authenticate existing PlayFab players inside the Photon environment. This means you may completely avoid implementing any user management for Photon.
  1. Navigate to DemoHub-Scene-V2 scene from the Photon Unity Networking Free package, the Classic version.
    • This scene is a hub for all the examples from the package.
    • As it is the first scene to load, let’s add a small script to enable authenticating PlayFab with Photon.
  2. Create an empty GameObject called PlayFabAuthenticator.
  3. Then in the Unity Inspector window, add a component with the same name to this GameObject.
Select the gear icon, then choose to edit the script from the drop-down menu. Copy and paste the code for the PlayFabAuthenticator component, and save and close the file.

Testing PlayFab to Photon authentication

  1. Start the scene.
  2. Inspect the flow of console messages. Control that:
  3. Authentication to PlayFab itself was successful.
  4. The Photon token was acquired.
The following picture illustrates the correct flow. Once the Photon token has been acquired, and authentication is complete, we are okay to check out the Photon demos. For example, start a demo called Demo Boxes.
  1. To ensure that the PlayFab authentication is complete, select Demo Boxes.
  2. Then select Load Demo, as shown on the following picture.
Photon starts outputting debug messages. By monitoring your console, you can easily spot if you have any authentication issues. Ensure that no Authentication Denied errors are present in the console. At this point, you have set up minimal PlayFab and Photon integration.

Photon room event + CloudScript

The Photon matchmaking system has the concept of a Room. If you aren’t familiar with this concept, consult with the Photon Matchmaking Guide. PlayFab allows you to intercept various room events. The following room events require only CloudScript to be intercepted:
  • RoomCreated
  • RoomJoined
  • RoomLeft
  • RoomClosed
The following events require extra control over Unity code to be intercepted (details are given later in this document):
  • RoomPropertyUpdated
  • RoomEventRaised
Once you introduce a handler for a room event, it becomes an essential part of the event handling flow. So errors produced while running your CloudScript may cause problems for the entire system. For example, if the RoomCreated handler throws an error, your clients will throw an error as well, and won’t be able to connect properly.
Let’s construct a PlayFab CloudScript by defining a handler for each event type individually.

Room Created handler

The RoomCreated handler is invoked every time a Photon room is created. The following CloudScript handler intercepts such events.
You may acquire more data about the event using the “args” argument.

Room Joined handler

The RoomJoined handler is invoked every time a player joins the room. The following CloudScript handler intercepts such an event.
This callback isn’t invoked for the first user entering the room. Use RoomCreated to intercept the first player that joins. You may acquire more data about the event using the “args” argument.

Room left

The RoomLeft handler is invoked every time a player leaves the room. The following CloudScript handler intercepts such event.
You may acquire more data about the event using “args” argument.

Room Closed handler

The RoomClosed handler is invoked every time the last player leaves the room and room has no players left. The following CloudScript handler intercepts such event.
You may acquire more data about the event using “args” argument.

Room Property Updated

The RoomPropertyUpdated handler is invoked every time the room property is changed. The following CloudScript handler intercepts such an event.
The currentPlayerId is undefined in this handler. If the room property was changed from the client, you may use the “args” argument, and refer to the UserId to acquire the player in charge.
You may acquire more data about the event using “args” argument.
When changing custom Room properties using the Unity Photon client, it is important to mark the call, so that it passes the event to Webhook (PlayFab in this case).

Room Event Raised

The Room Event Raised is called every time a custom room event is raised. The following CloudScript handler intercepts such an event.
You may acquire more data about the event using “args” argument.
When raising custom room events using Unity Photon client, it is important to mark the call so that it passes the event to Webhooks (PlayFab in this case).

Testing Room Event handlers

This example extends the previous example (PlayFab + Photon authentication). Upload the following CloudScript for your title.
The code does nothing more than posting a new title event whenever a Photon callback is invoked. Being of no use in production, this example lets us clearly see how the callbacks are invoked. Extend the PlayFabAuthenticator script by including new example code that raises a custom event, and set custom room property. The extended version also utilizes an Awake method to not destroy object between scene loads.
  • Run the hub scene and wait for PlayFab authentication to complete (1).
  • Then load the Boxes Demo scene (2).
  • Once the scene loads, wait for the peer to connect newly created room (1).
  • Then select Execute Example in the top left corner (2).
  • Observe the console output (3).
  • Make sure no errors have occurred.
Don’t forget to stop Unity from playing. This is done to ensure that we also receive RoomLeft and RoomClosed events. Navigate to the title Game Manager page, and observe the PlayStream panel. You should be able to see events generated as a result of our CloudScript code handling Photon events.
  1. Initially, our Photon instance had no opened room. When we launched the example, Photon has created the room for the Boxes Demo.
  2. The first player to join is the player who requested the room. So no RoomJoined Event was recorded. We then executed our example code:
    • First, we raised a custom Room Event.
    • Then, we set a custom Room Property.
    • Then we stopped the Unity play mode. This resulted in our client leaving the room.
  3. Since our disconnected client was the last one, there are no more clients and Photon closes the room.
All the events should be logged into the PlayStream event flow, as shown on the following picture. At this point, you have fully integrated Photon event support into your PlayFab title.
Last modified on August 10, 2026