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
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
So, as code example which will call delegateToCall if someone tries to close the window:
UGameInstance* instance = GetGameInstance();
UGameViewportClient* viewPortClient = instance->GetGameViewportClient();
If delegateToCall returns true, the window will be closed afterwards, if delegateToCall returns false, the close request will be ignored.