Creating an in-game console with UMG?

Hey guys,
I’m trying to make a console with UMG. The more complicated stuff I can figure out based on inputs and outputs, but how do I set up the basic structure of inputting and outputting text? It seems so commonplace but I can’t figure out how to do it in Unreal.

Thanks!

First off, I’m hoping that I understood your question correctly in that you want to create an in game console to enter console commands? If not then I apologize and this tutorial is useless to you. But I digress, on with what I got:

I handled this with a single widget (ConsoleWidget) that I create on BeginPlay in the player controller though you can create it wherever you see fit. The widget displayed below is how I have it set up in the designer. Simple border with a horizontal box as its only child. In the horizontal box is some Text “Console:” and an editable text box to the right.

The editable text box has an on text committed event which I bound in the widget seen below. Its important to switch on commit method because it calls default on creation and you don’t want it to disappear on creation.

When the text is committed (By pressing enter) it calls upon an event dispatcher that was bound to a custom event in the player controller on spawn seen below. It passes in string that is the command we entered.

I will cover close console later but first I set up an Action Mapping to toggle the console widget. I set mine to TAB but you can set it to whatever you want. I also created a boolean variable to check if the console is open, and another variable set to the console widget itself so we can keep track of it when we want to add it or remove it from the screen. Below is the how we toggle the console as well as what happens when we open or close the console.

When we call OpenConsole we add the widget to the viewport, we get its editable text box widget and set keyboard focus (this allows us to just start typing without having to click on the text box), set ConsoleOpen to true, and set our input mode. Close console does just the opposite; We remove the widget from the viewport, set ConsoleOpen to false, set our input back to game only. This is all toggled with TAB or any key of your choice. Going back to the third image, that is where we actually enter the console command. We get the string passed form the event dispatcher and call ExecuteConsoleCommand which is a built in Blueprint node.

Hope this helps or at the least be what you were searching for. :slight_smile:

This is absolute gold. Thank you! You’re a legend.