Reacting to events from other program

I have a separate program developed in C# that is producing data I want to share with a Unity game.
What is the best way to do that?

I’m new to Unity - please keep that in mind when answering :smiley:

I’m thinking about setting up some sort of messaging system to have both ends react (app and Unity) to messages. But I don’t want to over complicate it.

Another idea could be exchanging data through a simple textfile with date-time stamp. But to me that sounds like a setup that is not to stable. Maybe you have a different opinion and arguments?

Also I could develop and Rest API for the program and then have Unity query the endpoint for status data?

Or … what do you think?

I’m kind of hoping this is not the first time someone asks how to integrate data between Unity and an external app, and that there is a stable and proven way of doing just that :smiley:

The “hey as long as it works” way is:

  1. Your C# app write events/commands to a file (JSON data for example)
  2. Your Unity app reads the file (either periodically, or when it changes via FileSystemWatcher) and do whatever it is necessary.

Little bit harder:
Pipes. Check this CodeMonkey’s video.

What I would do:
An ASP.NET Core 8 API, especially using Minimal API syntax, literally 4 lines of code and you’ll have your API endpoint:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/api/hello", () => "Hello World!");

app.Run();

Want real-time, one or two-way communication?
Use ASP.NET Core + SignalR. It’s just one additional line of code (in addition to the Hub class code)

// Create a SignalR Hub called MainHub
app.MapHub<MainHub>("/hubs/main");