Table of Contents

Stride + SignalR

This example demonstrates real-time, two-way communication between a Stride application and a Blazor web application using a SignalR hub. It enables sending and receiving messages at runtime to synchronize game state and trigger in-game actions from the web UI.

This project shows how to:

  • Connect to a SignalR hub and register message handlers
  • Send commands and events from Stride to the Blazor app, and react to incoming messages
  • Drive in-game behaviors (such as creating entities) from the Blazor web UI

To run this example, first start the Blazor server app to host the SignalR hub (using IIS Express). Then, run the Stride application, which will connect to the hub and begin exchanging messages with the web UI.

For the full solution, including both the Stride project and the minimal Blazor server app with a SignalR hub, see the GitHub repository links below.

Note

This example requires the additional NuGet packages Stride.CommunityToolkit.Bepu, Stride.CommunityToolkit.Skyboxes and Stride.CommunityToolkit.Windows. Make sure to install all before running the code.

Stride + SignalR Example

View the Stride example on GitHub, and the minimal Blazor server app with SignalR hub here.

using Example17_SignalR.Scripts;
using Example17_SignalR.Services;
using Stride.CommunityToolkit.Bepu;
using Stride.CommunityToolkit.Engine;
using Stride.CommunityToolkit.Rendering.ProceduralModels;
using Stride.CommunityToolkit.Skyboxes;
using Stride.Core.Mathematics;
using Stride.Engine;

using var game = new Game();

game.Services.AddService(new ScreenService());

game.Run(start: (Scene rootScene) =>
{
    game.SetupBase3DScene();
    game.AddSkybox();
    game.AddProfiler();

    var screenManager = new Entity("ScreenManager")
    {
        new ScreenManagerScript()
    };
    screenManager.Scene = rootScene;

    var entity = game.Create3DPrimitive(PrimitiveModelType.Capsule);
    entity.Transform.Position = new Vector3(0, 8, 0);
    entity.Scene = rootScene;
});