Skip to main content
This sample demonstrates how to emit events from a Unity title to the PlayFab PlayStream pipeline. It covers the three main event scopes: player events, title events, and character events.

Requirements

Unity 2018.3+

The project was created with Unity 2018.3 and requires that version or later.

Visual Studio 2017+

Visual Studio 2017 (Update 15.7) or later is required to build the project.

PlayFab title

A PlayFab title with currency and catalog data imported.

PlayFab configuration

Before running the sample, import the bundled configuration files into your title via Game Manager:
Asset fileImport location
PlayFabEventsUnity_Currency.jsonEconomy → Currency
PlayFabEventsUnity_Characters.jsonEconomy → Catalogs
After import, update the Title ID in Assets/PlayFabSdk/Shared/Public/Resources/PlayFabSharedSettings.asset.

Setup

1

Clone the repository

git clone https://github.com/Myst0gan1/PlayFab-Samples.git
2

Open the project in Unity

In Unity Hub, click Open and navigate to:
PlayFab-Samples/Samples/Unity/PlayFabEventsUnity
3

Import the configuration assets

In Game Manager, import PlayFabEventsUnity_Currency.json under Economy → Currency and PlayFabEventsUnity_Characters.json under Economy → Catalogs.
4

Set your Title ID

Open Assets/PlayFabSdk/Shared/Public/Resources/PlayFabSharedSettings.asset in the Unity Inspector and replace the placeholder Title ID with your own.
5

Open the sample scene and play

Open the scene from Assets/Scenes/, then press Play in the Unity Editor.

Using the sample

The sample displays a set of buttons, each mapped to a specific event type:
  1. Click any button to fire the corresponding event to PlayFab.
  2. Open Game Manager → Analytics → PlayStream to observe the event appear in real time.
Keep the PlayStream monitor open in a browser tab while you click buttons in the Unity editor. Events typically appear within a few seconds.

Event scopes

Scoped to a specific player. Use the WritePlayerEvent API. Ideal for tracking individual player actions such as level completion, item use, or quest progress.
Scoped to the entire title rather than a single player. Use the WriteTitleEvent API. Useful for server-wide occurrences or administrative triggers.
Scoped to a specific character owned by a player. Use the WriteCharacterEvent API. Requires at least one character to exist on the account, which is why the character catalog must be imported first.

Key PlayFab features

WritePlayerEvent

Sends a custom event associated with the logged-in player to the PlayStream pipeline.

WriteTitleEvent

Sends a custom event associated with the title (not any specific player).

WriteCharacterEvent

Sends a custom event associated with a specific character belonging to a player.

PlayStream

Real-time event pipeline in PlayFab that receives events, evaluates rules, and can trigger automation actions such as CloudScript execution or push notifications.

Build docs developers (and LLMs) love