GFN on mobile
Last updated
Last updated
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:
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)
Known issue: On iOS, there seems to be a bug with this flow. Tapping on an input box that has a GFN action zone over the top will sometimes both focus the in-game text box and bring up the keyboard, but will sometimes only do one or the other action, meaning you are incapable of typing into the in-game text box. This is pretty finnicky, but usually works after a few attempts. This is being investigated.
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.
Important: This function uses GetCachedGeometry
to determine the bounds of the widget. This function gets the last geometry used to tick the widget. This may not be the correct geometry if called too early, e.g. if you are moving the widget, or the widget was only recently constructed. For this reason, we recommend waiting a couple of ticks after construction (or having stopped moving the widget) before calling it.
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?)