Unity SDK
Integrate the Shard SDK into your Unity project for recording, error monitoring, and social events.
Prerequisites: Unity 2019.4+ and Shard Launcher running
Installation
Option 1: Unity Package Import
- Download
ShardSDK.unitypackagefrom GitHub Releases - In Unity, go to Assets → Import Package → Custom Package
- Select the downloaded
.unitypackagefile - Click Import to add the SDK to your project
Option 2: Unity Package Manager (UPM)
Add the following to your Packages/manifest.json:
{
"dependencies": {
"com.shard.sdk": "https://github.com/shard-dev/shard-platform.git?path=packages/sdk-unity"
}
}Quick Start
The SDK auto-initializes when your game starts. Access features via the ShardSDK static class:
using Shard;
public class GameManager : MonoBehaviour
{
void OnBossDefeated()
{
// Trigger a recording event
ShardSDK.Recording.TriggerEvent("myGame_bossDefeated");
}
void OnError(Exception ex)
{
// Report an error
ShardSDK.Monitor.ReportError(ex.Message, ex.StackTrace);
}
void OnAchievementUnlocked()
{
// Trigger a social event
ShardSDK.Social.TriggerEvent("myGame_achievementUnlocked");
}
}Configuration
Customize the SDK by initializing with a custom config before the first API call:
using Shard;
public class SDKInitializer : MonoBehaviour
{
void Awake()
{
var config = new ShardConfig
{
LauncherUrl = "http://localhost:9876", // Default
EnableRecording = true,
EnableMonitor = true,
EnableSocial = true
};
ShardSDK.Initialize(config);
}
}Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
LauncherUrl | string | http://localhost:9876 | Shard Launcher URL |
EnableRecording | bool | true | Enable recording triggers |
EnableMonitor | bool | true | Enable error reporting |
EnableSocial | bool | true | Enable social events |
Basic Usage
Recording Events
Trigger recording when gameplay moments occur:
// Trigger a recording event
ShardSDK.Recording.TriggerEvent("myGame_e5f6g7h8");Error Monitoring
Report errors and exceptions:
// Report an error with message only
ShardSDK.Monitor.ReportError("Player fell through floor");
// Report an error with stack trace
try
{
// risky code
}
catch (Exception ex)
{
ShardSDK.Monitor.ReportError(ex.Message, ex.StackTrace);
}Social Events
Trigger social content display:
// Trigger a social event
ShardSDK.Social.TriggerEvent("myGame_a1b2c3d4");Error Handling
The SDK uses fire-and-forget HTTP calls with silent failure:
- If the Shard Launcher is not running, calls silently fail
- No exceptions are thrown to your game code
- Network timeouts are handled automatically (5 second timeout)
Your game continues running normally even if the launcher is unavailable.
Next Steps
- API Reference - Full API documentation
- Recording Overview - Learn about recording features
- Error Tracking - Learn about error monitoring
- Social Events - Learn about social features
- ShardKit CLI - Generate event IDs with the CLI