Avoid multiple instances of an application

Hi everyone!

Does anybody know if there is a way, at Unreal’s engine level, to prevent from having multiple instances of your application running? I mean, once you have your app packaged, if you try to open multiple times the ‘exe’, the application should only launch the first time. Subsequent times, the only effect should be to gain focus of the unique instance you previously launched.

Thanks in advance,

2 Likes

Hi. Maybe for somebody still actual.

Check my plugin:
https://www.unrealengine.com/marketplace/en-US/product/checkappinstance

https://github.com/mrbindraw/CheckAppInstance

Enjoy!

2 Likes

love it but ur gist is gone.

1 Like

Hi! Yes I know)
This is same code distributed via ue marketplace like code plugin (free)

Have a epic day!

3 Likes

@Andrew_Bindraw Thx, ur code is so brief and powerful.

But is it possible to move the loading phase earlier?
For example, check the file lock before the window popup, so starting second instance won’t see a new blank window.

We write a plugin, plug & play, just enable the plugin then things get done, starting second UE5 instance won’t see a new blank window now.

@BBB @Andrew_Bindraw I think the solution in your posts is overly complicated. Instead of using a file lock, you could just use FGenericPlatformProcess::IsFirstInstance()

If this is a Windows packaged game, a simple way is to use a named mutex. Create the mutex when the application starts; if it already exists, you know another instance is running. You can then bring the existing window to the foreground and exit the second process. For Unreal, you can do this in C++ during startup using the Windows API (CreateMutex). Just make sure the mutex name is unique to your application. This is generally more reliable than checking for the process name, since the same executable could potentially be launched from different paths.