Playgen: Unity SDK Integration

Integrating Playgen with Your Game using the Unity SDK

Playgen is the AI-driven platform for taking your mobile games from seed to scale. Playgen automates asset generation, economy balancing, and experience personalization, enabling fast iteration loops and autopilot growth.

Metagen is a live personalized experience optimization engine. It eliminates the need to manually design, adjust, test, and segment player progression and offers. Metagen enables game developers to stop wasting cycles on finding arbitrary numbers and focus instead on perfecting the core experience.

Optimization in Metagen is done in real-time using live player behavior, while user segments are discovered and handled organically, to find just the right experience parameters for each and every player.

This quick start guide provides a brief overview of the steps required to integrate the Playgen Unity SDK into your game.

Getting Started

Step 0: Install the Newtonsoft JSON Dependency

Add the Newtonsoft JSON Unity package to your project. The Playgen SDK is tested against versions >= 3.2.x. If the package is not already installed:

  1. Click Window -> Package Manager

  2. Click on the + button and select Add package by name…

  3. Enter com.unity.nuget.newtonsoft-json and click Add

Step 1: Install the Playgen Unity Package

  1. Click Assets -> Import Package -> Custom Package…

  2. Import the provided PlaygenPlatform.unitypackage

Step 2: Configure Settings

  1. In Unity, click Window -> Playgen to show the Playgen settings tab.

  2. Fill in the project’s API key and secret, which can be found in the project’s dashboard.

Step 3: Design the Experience Schema

Our teams will collaborate to identify the key experience measurements and design together a corresponding experience schema to control the extents to which Metagen will optimize your game.

The designed schema will automatically be imported to /Assets/Config/metagen.json when you import the Playgen Unity package. It will look something like this:

{
	"experiments": {
		"core": {
			"fields": {
				"points": {
					"type": "int",
					"min": 0,
					"max": 1000,
					"default": 100
				},
				"special_level": {
					"type": "bool",
					"default": false
				},
				"enemy": {
					"type": "object",
					"fields": {
						"hp": {
							"type": "int",
							"min": 50,
							"max": 200,
							"default": 100
						},
						"attack": {
							"type": "int",
							"min": 5,
							"max": 50,
							"default": 20
						},
						"defense": {
							"type": "int",
							"min": 5,
							"max": 50,
							"default": 15
						}
					}
				}
			}
		}
	}
}

Step 4: Initialize the Playgen SDK

Add the following code snippet to your game initialization script to set up the Playgen SDK as soon as the game starts, ideally in the loading scene. Passing the current player id is optional but recommended for later data analysis.

// Initialize the Playgen SDK
Playgen.Core.Initialize(playerId: "YourCurrentPlayerId", () => {
	// Called once the Playgen initialization is done.
	Debug.Log("Playgen initialized successfully.");
});

Step 5: Get Player Experience Parameters

Use the following code to get a specific game experience based on the current player.

// For quick and simple access
using static Playgen.Core;
// Retrieve the special level flag from the core experiment
GetExperienceFor<bool>("core.special_level", defaultValue: false)
// Retrieve the Enemy HP (the default value is optional)
GetExperienceFor<int>("core.enemy.hp")

Step 6: Report Player Behavior

Metagen automatically measures playtime and session length, so no special reporting is needed for this. The following methods can be used to report IAP, RV, custom monetization events, and custom metrics to the platform:

using static Playgen.Core;

// Report In-App-Purchase
ReportIAP(new {
	id = "gold_pack_01",
	name = "Basic Gold Pack",
	price = 4.99,
	currency = "USD"
});

// Report Rewarded Video
ReportRV(new {
	id = "rewarded_video_01",
	priceEstimate = "0.10",
	currency = "USD"
});

// Report a Custom Monetization Event
ReportMonetization(new {
	id = "subscription_01",
	kind = "subscription",
	name = "Monthly VIP Subscription",
	amount = 9.99,
	currency = "USD"
});

// Report a Custom Metric
ReportMetric(new {
	id: "battle_pass_completion_time",
	value: 120
});

Step 7: Crack a Beer

That’s it! Enjoy a cold one. The Metagen platform will tirelessly work behind the scene to find the right experience for each and every player. Check the organization admin panel to see your experiments, keep an eye on where the metrics are heading, and review what’s being tested.

Questions

What happens if your platform is down?

Every experience parameter has a generic default value that ships with your build. Every personalized experience parameter is cached locally. The experience always degrades gracefully. At worst, the player experience will be a bit behind the iterative optimization process for a while.

Web requests during the SDK initialization have a configurable timeout of less than one second, to avoid any chance of slowing down the initial loading experience.

Is there an API we can directly integrate with?

Yes, we offer a fully-RESTful API for interactions with players, experiments, branches, and any other part of our platform. However, the SDK is the recommended integration approach for Unity games as it offers a more fully-featured and streamlined experience and a much simpler integration process.

How are different versions and environments handled?

As automatically as possible. Development and production environments are detected and handled separately. Experiment versions are auto-locked against your game’s build version. Player experience is migrated automatically when needed to support schema changes. The goal is to reduce maintenance chores and focus on the experience.