I would like to catch the event of an “alt+f’4” command from a player, in order to do proper exit (Save of the progress/clean…). Is there a way to achieve this inside UE4 ? If not, is it possible to block totally the event and its effect ?
I’m not even going to ask why you’d want to do this, but you’ll need to find somewhere to intercept the native windows event “WM_CLOSE” in the engine. I’d suggest as a starting point searching the source code for that to see where it’s mentioned (I’d bet that it is used somewhere) and then figure out how to block it.
Actually, at first, I just wanted to add a warning in case of a player quit by using alt-f4 if he’s playing in a ranked multiplayer match. (Because quitting during a match cause the player to be ban of the matchmaking for a while, and lose a lot of ELO score). It’s a feature we usually see in multiplayer game, so I was wondering if there was a built-in way to achieve this in UE4.
Anyway, thanks for your help, I will do this by the old fashion way :).
Just in case that someone is looking for the same thing, you can disabling the system message in the WindowsApplication.cpp that you can found the engine source (l.731 in the 4.9 version).
Actually you can also handle window close requests in user code, without ever touching the engine source.
The viewport client does have a delegate for exactly that purpose, which can be obtained by the UGameViewportClient::OnWindowCloseRequested() accessor.
The world viewport client can be obtained with the UGameInstance::GetGameViewportClient() method, but beware that this is only available after the GameInstance has been initialized, but not yet in the UGameInstance::Init() method.
So, as code example which will call delegateToCall if someone tries to close the window:
inside the engine the closest hook is UGameViewportClient::OnWindowCloseRequested, bind it after the game instance is up and return false to ignore the close. that covers alt+f4 cleanly when the request comes through the viewport.
but that delegate never fires for a kill from task manager or a crash, so for an exhibit you want a second layer outside the game. to lock down a packaged UE5 game on a public screen, Kiosk Lockdown Toolkit is a kiosk mode plugin for Unreal Engine 5 whose keyboard filter swallows alt+f4 before it becomes a close, and its watchdog helper relaunches the app after a crash or kill: Kiosk Lockdown Toolkit — Block Alt+Tab, Win Key & Taskbar for Kiosks | Fab
normal Quit Game does not trigger the relaunch, only crashes and kills, which is the behavior you want for unattended screens.