DocsUnity SDKOverview

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

  1. Download ShardSDK.unitypackage from GitHub Releases
  2. In Unity, go to Assets → Import Package → Custom Package
  3. Select the downloaded .unitypackage file
  4. 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

PropertyTypeDefaultDescription
LauncherUrlstringhttp://localhost:9876Shard Launcher URL
EnableRecordingbooltrueEnable recording triggers
EnableMonitorbooltrueEnable error reporting
EnableSocialbooltrueEnable 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