Skip to main content

Quickstart Guide

Welcome to PlaySafe!

This guide will walk you through installing and setting up the PlaySafe Unity SDK in your project.

Prerequisites

Before we begin, make sure you have the following:

  • Unity 2021.3 or a higher version installed.
  • A PlaySafe App Key. Need one? Reach out to the PlaySafe team at [email protected] or visit the PlaySafe Dashboard if you already have an account.

Installation & Setup

Follow these steps to integrate the PlaySafe SDK into your Unity project.

Step 1: Import the SDK via Package Manager

The easiest way to install the SDK is directly from its Git repository using the Unity Package Manager.

  1. In your Unity Editor, go to Window > Package Manager.

    Accessing Package Manager Window Option

  2. Click the '+' (plus) icon in the top-left corner of the Package Manager window.

  3. Select "Add package from git URL..." from the dropdown menu.

    Add Package from Git URL option

  4. Enter the following Git URL into the text field: https://github.com/dogelabsvr/PlaySafe-UnitySDK.git

  5. Click Add. Unity will now download and import the SDK package into your project.

You should see the PlaySafe SDK listed under your project's Packages folder once the import is complete.

PlaySafe package folder structure

Step 2: Set up the PlaySafe Manager

The SDK requires a dedicated GameObject in your scene to manage its operations.

  1. In your Hierarchy window, create a new empty GameObject. Right-click in the Hierarchy panel and select Create Empty.

  2. Rename this new GameObject to PlaySafeManager.

    Creating the PlaySafeManager GameObject

  3. With the PlaySafeManager GameObject selected, go to the Inspector window.

  4. Click Add Component.

  5. Search for PlaySafeManager and select the script to add it as a component.

    Locating the PlaySafe Manager script

    Adding the PlaySafe Manager script component

Step 3: Configure the PlaySafe Manager

Now, let's configure the PlaySafeManager component with your App Key.

  1. Select the PlaySafeManager GameObject in your Hierarchy.

  2. In the Inspector, you'll see the PlaySafeManager component with several fields. The most important one is the App Key.

    PlaySafe Manager component configuration fields

  3. You'll need to paste your unique PlaySafe App Key into this field. If you don't have one yet, follow the next step!

Step 4: Generate Your App Key (If Needed)

If you haven't generated an App Key yet, here's how to do it from the PlaySafe Dashboard:

  1. Log in to your PlaySafe Dashboard.

  2. Navigate to the App Keys section using the sidebar menu.

    Navigating to App Keys in PlaySafe Dashboard

  3. Click the Generate App Key button.

    Generate App Key button location

  4. A dialog box will appear that allows you to create your new app key. Once generated, click the Copy button to copy it to your clipboard. Make sure to store this key securely, as it won't be shown again.

    Generate App Key dialog box with copy option

  5. Go back to the Unity Editor, select your PlaySafeManager GameObject, and paste the copied key into the App Key field in the Inspector.

Testing the Integration

The SDK package includes a demo scene to help you verify that everything is set up correctly.

  1. Navigate to the Packages/PlaySafe/Samples folder in your Project window.

    PlaySafe Demo folder location

  2. You'll find the demo assets, including the PlaySafeDemo scene. You can either test the demo by copying this scene into your Assets folder (if you're just looking around and trying to understand how PlaySafe works), or by adding the PlaySafeDemoIntegration script to your PlaySafeManager Game Object.

    Files within the PlaySafe Demo folder

3a. If you do choose to open the PlaySafeDemo scene:

  • Ensure the PlaySafeManager GameObject in the demo scene has your App Key pasted into its configuration in the Inspector (similar to Step 3 & 4 above, but for the GameObject within the demo scene). The demo scene already contains a PlaySafeManager game object.

3b. If you instead would like to integrate PlaySafe into your game, then follow this:

  • Add the the PlaySafeDemoIntegration script to the PlaySafeManager Game Object.

    Typical Game Object setup in the PlaySafe Demo scene

  • On the PlaySafeDemoIntegration component created, assign the PlaySafeManager script to the Play Safe Manager reference Adding PlaySafeManager component in the Demo scene if necessary

  1. Enter Play mode in the Unity Editor.

  2. Interact with the demo scene as intended (this might involve triggering voice input if the demo supports it).

  3. Check the Unity Console window for logs from PlaySafe. You should see messages indicating that PlaySafe has initialized and is processing audio (if applicable).

    Example PlaySafe logs in the Unity Console

  4. Go back to your PlaySafe Dashboard and navigate to the Live Feed section.

    Navigating to Live Feed in PlaySafe Dashboard

  5. You should see data coming in from your Unity application, confirming that the SDK is successfully communicating with the PlaySafe backend.

    Example data appearing in the PlaySafe Live Feed

If you see logs in the Unity console and data appearing in your PlaySafe dashboard, congratulations! You've successfully integrated the PlaySafe SDK.

Integrating the SDK

The PlaySafeDemoIntegration.cs file serves as your starting point for integrating PlaySafe into your game. Here's what it includes:

Core Integration Methods

The integration requires implementing three essential methods:

1. CanRecord() - Define when PlaySafe should record audio

private bool CanRecord()
{
// Example settings to choose when to listen to microphone
bool IsMicrophoneMuted = false; // TODO: Replace this with your game logic
bool IsInMultiplayerLobby = true; // TODO: Replace this with your game logic
int playerCount = 3; // TODO: Replace this with your game logic

return !IsMicrophoneMuted &&
IsInMultiplayerLobby &&
playerCount >= 2;
}

2. GetTelemetry() - Provide player and session information

private PlaySafeManager.AudioEventRequestData GetTelemetry()
{
string userId = "1234"; // TODO: Replace with your actual user ID
string roomName = "ExampleRoom"; // TODO: Replace with your actual room ID
string language = Application.systemLanguage.ToString();

return new PlaySafeManager.AudioEventRequestData()
{
UserId = userId,
RoomId = roomName,
Language = language,
};
}

3. OnActionEvent() - Handle moderation actions

private void OnActionEvent(ActionItem actionEvent, DateTime serverTime)
{
string duration = actionEvent.DurationInMinutes >= 60 ?
$"{(actionEvent.DurationInMinutes / 60f).ToString("F1")} hours" :
$"{actionEvent.DurationInMinutes} minutes";

Debug.Log($"Voice chat disabled for {duration}. This can happen due to using slurs, fighting, or general disrespectful behavior");

DateTime bannedUntil = serverTime + System.TimeSpan.FromMinutes(actionEvent.DurationInMinutes);

// TODO: Add your game-specific logic here
// For example: DisableVoiceChat(bannedUntil);
}

Using Async API Methods

The SDK provides several async methods for advanced functionality:

Player Status Checking

var playerStatus = await playSafeManager.GetPlayerStatusAsync();
Debug.Log($"Player has violation: {playerStatus.Data.HasViolation}");

Sensei Poll Management

// Get active poll for a persona
string personaId = "your-persona-id"; // From PlaySafe dashboard
var poll = await playSafeManager.GetActivePollAsync(personaId);

// Cast a vote
if (poll != null && poll.Data != null)
{
var vote = await playSafeManager.CastVoteAsync(poll.Data.Id, "yes");
var results = await playSafeManager.GetPollResultsAsync(poll.Data.Id);
}

Setup Process

  1. Copy the PlaySafeDemoIntegration.cs file into your project
  2. Modify the GetTelemetry() method to return your actual user and room data
  3. Update the CanRecord() method to match your game's voice chat conditions
  4. Implement your game-specific logic in the OnActionEvent() method
  5. Assign the script to your PlaySafeManager GameObject and link the references

For detailed API documentation, see the API Reference section.

Next Steps

Now that the SDK is installed and tested, you can start integrating its [features](todo: add features) more deeply into your game. Explore the other documentation sections to learn about:

  • Recording and processing audio events for toxicity detection.
  • Handling moderation events (reports & mutes).
  • Customizing SDK behavior.

In case of anything, feel free to reach out to us at [email protected] or via Discord.