Gamemode.h Blueprint keyboard input to quit gamemode


I have tried to build something into my gamemode, so that when I press “Escape” game shuts down. script I built is very simple, and shown below.

thing is breakpoint is never hit when I press button. I have tried a working keyboard input, which works in my character blueprint.

It strikes me that because Gamemode Blueprint inherits from Gamemode.h much of input doesn’t work, for example “Enable Input” can’t be dragged into Gamemode blueprint?


What is correct way of getting this to work? Have character flag that end is nigh and then game mode shutdown based on character?

I have checked defaults and believe that Gamemode blueprint is pointing at Playercontroller, yet still no input routes through to Blueprint:

Hey PompeyPaul,

To enable input in GameMode BP, you’ll first need to Get Player Controller and then drag off that to find Enable Input node. If you do that on Event Begin Play, your GameMode will be able to accept your InputAction Quit.

It is generally bad practice to have any input going through your GameMode if not necessary, though it is possible. Instead, you could set this up in your Player Controller or in your HUD.

Hope that helps!

Thanks for info. Why is it bad practice for GameMode to take input? I think it would be even odder to have HUD handle the “Quit Game” event than Game Mode?

Made changes and it now works sweetly =D

GameMode is used across entirety of your game, so it’s generally best to use it as little as possible for functions that could be used in a smaller, more contained BP. Any input used in GameMode BP can be used by any player at any time at any point in game, and that may be what you want but it may also cause more problems down line when you want to make changes to game, convert it to multiplayer, etc. There are always exceptions, but that’s general reasoning: modular design would have you place these functions in a safer place.

Glad you got it working, though! Let me know if you have any other trouble with it.

Thanks. Does GameMode persist across level loads?

No it does not, each level can have its own game mode. flow would be GameModeA → TransitionGameMode → GameModeB.

You can read more about Game Modes here: