GFN on Mobile

When running a game through GFN on a mobile device, there are some extra considerations to make, that will require manual work in your project:

Input text boxes bringing up virtual keyboards

Some context on the problem

On mobile, to be able to type in in-game text boxes, since you will most likely not have a keyboard attached, you will need to bring up a virtual keyboard.

Unfortunately, this is not done automatically for you. GFN has no game knowledge to know when to bring up the virtual keyboard, and this cannot be triggered by the game when the keyboard is focused. Instead, the way GFN works is by defining "action zones", that will trigger a certain action when touched. If you define a "GFN Edit Box" over the in-game editable text box, then tap on that region, then the editable text box will be focused, and so take input text, and the virtual keyboard will be brought up, allowing you to type. If either of these don't happen you will be unable to enter the text (if the keyboard is brought up, but the in-game widget is not focused, then the widget will not receive the typed text)

An example of an in-game editable text box. The blue outline shows the bounds of the widget - a GFN edit box would need to be created with these bounds so that it matches the focusable region of the widget underneath

How to define GFN regions

NOTE: The following functionality is present from release v33. If you are on an earlier release, please get in touch for alternative solutions.

GFN Regions can be defined with the UpdateGFNRegionForWidget helper function. This takes a widget and a GFN Input ID integer. This integer is used to associate the region with a specific widget, so that moving or hiding the widget updates the right corresponding region.

To get a unique ID for your particular widget, you can call GetNextGFNInputId

Internally, this calls either DisableGFNEditableTextBoxRegion, which turns off the "GFN Edit Box" associated with the provided ID, or calls SetGFNEditableTextBoxRegion, which makes a "GFN Edit Box" of the assigned dimensions for the provided ID. We have a helper function SetGFNRegionForWidget that gets the bounds of the provided widget and uses them as the text box region.

NOTE: Since this edit box is entirely separate to the Unreal game itself, it has no knowledge of whether the associated widget is visible or not. It is your responsibility to maintain the edit box, e.g. by recalling UpdateGFNRegionForWidget whenever your widget moves or is hidden.

See WBP_M2Example_SettingsMenu for an example of GFN regions being managed. On construction, it reserves GFN Input Ids for each EditableTextBox widget, and when the settings menu is shown or hidden, it refreshes the GFN regions for each widget.

NOTE: It adds two frames of delay, to make sure that calling GetCachedGeometry on the widget returns the correct size and position. Without the delay, the widget may not have been drawn to the screen yet, and so may not have any geometry to retrieve. (You can test this by adding a breakpoint inside SetGFNRegionForWidget and observing the value being passed into TopLeftPosition - is it (0,0), instead of what you'd expect it to be?)

Last updated

Was this helpful?