DocsMonoGame SDKOverview

MonoGame SDK

Integrate the Shard SDK into your MonoGame/.NET project for recording, error monitoring, and social events.

Prerequisites: .NET 6.0+ (or .NET Standard 2.0 compatible) and Shard Launcher running


Installation

Install via NuGet Package Manager:

dotnet add package ShardSDK.MonoGame

Or via Package Manager Console in Visual Studio:

Install-Package ShardSDK.MonoGame

Quick Start

⚠️

Important: Unlike Unity, MonoGame requires explicit initialization. Call ShardSDK.Initialize() before using any SDK features.

using Shard;
 
public class Game1 : Game
{
    protected override void Initialize()
    {
        // Initialize the Shard SDK
        ShardSDK.Initialize();
        
        base.Initialize();
    }
 
    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

Initialize with custom configuration:

using Shard;
 
public class Game1 : Game
{
    protected override void Initialize()
    {
        var config = new ShardConfig
        {
            LauncherUrl = "http://localhost:9876",  // Default
            EnableRecording = true,
            EnableMonitor = true,
            EnableSocial = true
        };
        
        ShardSDK.Initialize(config);
        
        base.Initialize();
    }
}

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)
  • Uses System.Net.Http.HttpClient for HTTP requests

Your game continues running normally even if the launcher is unavailable.


Next Steps