Restricting exported project to running in a single instance

Godot Version

4.3rc1

Question

I’ve recently found out (by accident) that all exported Godot project can be run in multiple instances. As in if your game is running you can launch another copy of the game and have it running at the same time. On Windows (and maybe Linux?) it’s as easy as just picking the top item in the task bar menu, but by opening a file from the OS (Open with… and pick the game) you can launch multiple instances of the exported game on windows, linux and macOS (which generally doesn’t have multiple instances of running apps).

In some cases this might be harmless or even desirable, but in other cases this might be something that could cause issues and you want to avoid. I’ve therefore opened a proposal to add a “single instance” option for exports Allow restricting exported game to be a single-instance process · Issue #10208 · godotengine/godot-proposals · GitHub (check it out and support it if this is something you’d like as well!)

However, this will likely take time if it’s ever implemented. So now I’m wondering how I could handle this in the meantime:

  • Is there something I could manually do to the exports to prevent multiple instances running on different platforms?
  • Is there some way I could detect if multiple instances of my project are running after launch (if I can’t prevent launching)?