Skip to content

Menu Item Widget

Introduction

A widget used to display a title, text and value in the form of a menu item

Dependencies

The MenuItem relies on other components of this plugin to work:

  • Logger: Used to log useful information to help you debug any issues you might experience
  • Game Instance: Used to monitor for input device changes and handle saving/loading game data
  • Audio: Used to play sound effects either 2D or at a specified location

Optional Widgets

You can add the following widgets to enable extra functionality:

Name Description Type
Title The TextBlock used to display the title of the menu item UTextBlock*
NormalText The TextBlock used to display the text of the menu item while not highlighted UTextBlock*
HighlightedText The TextBlock used to display the text of the menu item while highlighted UTextBlock*
ValueText The TextBlock used to display the current value of the menu item UTextBlock*
HighlightedValueText The TextBlock used to display the current value of the menu item while highlighted UTextBlock*
SelectButton The button used to select the menu item UButton*
ValueSlider The slider used to display and update the current value of the menu item USlider*
IncreaseValueButton The button used to increase the value of the menu item UButton*
DecreaseValueButton The button used to decrease the value of the menu item UButton*
BorderLeft The border displayed on the left of the menu item UImage*
BorderRight The border displayed on the right of the menu item UImage*
BorderBackground The background border display in the menu item UImage*
ButtonLeft The button displayed on the left of the menu item UImage*
ButtonRight The button displayed on the right of the menu item UImage*
ButtonBackground The background button display in the menu item UImage*
InputIndicator The background button display in the menu item UImage*

Optional Animations

You can add the following widgets to enable extra functionality:

Name Description
HighlightedAnimation The animation played when the menu item is highlighted

API Reference

Properties

Property Description Type Default Value
HighlightedAnimation The animation played when the menu item is highlighted UWidgetAnimation* nullptr
FocusByDefault Should the menu item be focused by default? bool false
HideOnConsoles Should the menu item be hidden on consoles? bool false
TitleText The title text displayed in the menu item FText
MenuItemText The text displayed in the menu item FText
HighlightedSFX The sound effect played when the menu item is highlighted USoundBase* nullptr
BorderNormalColor The color of the border when not highlighted FLinearColor
BorderHighlightedColor The color of the border when highlighted FLinearColor
BorderNormalImage The image of the border when not highlighted UTexture2D* nullptr
BorderHighlightedImage The image of the border when highlighted UTexture2D* nullptr
BorderLeftNormalImage The image of the left border when not highlighted UTexture2D* nullptr
BorderLeftHighlightedImage The image of the left border when highlighted UTexture2D* nullptr
BorderRightNormalImage The image of the right border when not highlighted UTexture2D* nullptr
BorderRightHighlightedImage The image of the right border when highlighted UTexture2D* nullptr
BackgroundNormalColor The color of the button when not highlighted FLinearColor
BackgroundHighlightedColor The color of the button when highlighted FLinearColor
BackgroundNormalImage The image of the button when not highlighted UTexture2D* nullptr
BackgroundHighlightedImage The image of the button when highlighted UTexture2D* nullptr
BackgroundLeftNormalImage The image of the left button when not highlighted UTexture2D* nullptr
BackgroundLeftHighlightedImage The image of the left button when highlighted UTexture2D* nullptr
BackgroundRightNormalImage The image of the right button when not highlighted UTexture2D* nullptr
BackgroundRightHighlightedImage The image of the right button when highlighted UTexture2D* nullptr
ValueUpdateMethod The method used to update the value of the menu item EMenuItemValueUpdateMethod EMenuItemValueUpdateMethod::SinglePress
IncrementSinglePress The increment used when updating the value when the key is pressed float 1.0f
IncrementHold The increment used when updating the value when the key is held down float 0.15f
SettingsItemType The type of setting item managed by this menu item (changing this will overwrite other settings) ESettingsItemType ESettingsItemType::None
AutoSaveSettingsOnValueChanged Should the settings managed by this menu item automatically be saved when the value is changed? bool true
AutoSaveSettingsOnHighlightRemoved Should the settings managed by this menu item automatically be saved when the highlight state is removed? bool true
AutoSaveSettingsOnSelected Should the settings managed by this menu item automatically be saved when the menu item is selected? bool true
InputDevice The input device associated with the action to rebind EInputDevice EInputDevice::Unknown
InputMappingContext The input mapping context containing the action to rebind UInputMappingContext* nullptr
InputAction The input action to rebind UInputAction* nullptr
MappableName The player mappable name for the action to rebind FName
ShowValueSlider Should the value slider be shown for this menu item? bool false
ShowValueButtons Should the increase/decrease value buttons be shown for this menu item? bool false
ValueMapping A mapping of possible values to text TMap<int, FText>
DefaultValue The default value of the menu item int 100
MinValue The minimum value of the menu item int 0
MaxValue The maximum value of the menu item int 100
AllowSelection Can the menu item be selected? bool true
VerticalNavigation The type of navigation used by the menu item when pressing the up or down key EMenuNavigation EMenuNavigation::HighlightItem
MenuItemUp The menu item highlighted when the up key is pressed UMenuItem* nullptr
MenuItemDown The menu item highlighted when the down key is pressed UMenuItem* nullptr
HorizontalNavigation The type of navigation used by the menu item when pressing the left or right key EMenuNavigation EMenuNavigation::HighlightItem
MenuItemLeft The menu item highlighted when the left key is pressed UMenuItem* nullptr
MenuItemRight The menu item highlighted when the right key is pressed UMenuItem* nullptr
Menu A reference to the menu that contains this menu item UMenu* nullptr

Events

Name Description Params
OnSelected Event used to notify other classes that the menu item was selected
OnSelectedInContainer Event used to notify other classes that a specific menu item in the container was selected Index (int)
The index of the menu item that was selected
OnHighlighted Event used to notify other classes that the menu item was highlighted
OnHighlightRemoved Event used to notify other classes that the menu item's highlighted state was removed
OnValueChanged Event used to notify other classes that the menu item's value was updated Value (int)
The new value of the menu item

Functions

Name Description Params Return
SetText Set the text displayed in the menu item Text (FText&)
The new text displayed in the menu item
SetTitle Set the title displayed in the menu item Text (FText&)
The new title displayed in the menu item
SetHighlightedState Set the highlighted state of the menu item IsHighlighted (bool)
Is the menu item highlighted?

PlayHighlightedAnimation (bool)
Should the highlighted animation be played?

PlayHighlightedSound (bool)
Should the highlighted sound effect be played?
IsHighlighted Check if the menu item is highlighted bool
A boolean value indicating if the menu item is highlighted
GetValue Get the current value of the menu item int
The current value of the menu item
UpdateValue Update the value of the menu item Increment (float)
The amount added to the current value of the menu item
SelectItem Select the menu item
SaveSettings Save the settings managed by this menu item
ApplySettings Apply the settings managed by this menu item
GetInputActionKey Get the key used by the specified input action FKey
The key used by the specified input action
OnMenuBack Called when trying to go back in the menu bool
A boolean value indicating if the back event was handled
AnyKeyPressed Called after any key is pressed by the player (used to remap controls) Key (FKey)
The key pressed by the player
ApplyKeyBinding Apply the key binding for the input action
IsWaitingForKeyPress Is the menu item waiting for a key press? bool
A boolean value indicating if the menu item is waiting for a key press

Blueprint Usage

You can use the MenuItem using Blueprints by adding one of the following nodes:

  • Ultimate Starter Kit > UI > Set Text
  • Ultimate Starter Kit > UI > Set Title
  • Ultimate Starter Kit > UI > Set Highlighted State
  • Ultimate Starter Kit > UI > Is Highlighted
  • Ultimate Starter Kit > UI > Get Value
  • Ultimate Starter Kit > UI > Update Value
  • Ultimate Starter Kit > UI > Select Item
  • Ultimate Starter Kit > UI > Save Settings
  • Ultimate Starter Kit > UI > Apply Settings
  • Ultimate Starter Kit > UI > Get Input Action Key
  • Ultimate Starter Kit > UI > On Menu Back
  • Ultimate Starter Kit > UI > Any Key Pressed
  • Ultimate Starter Kit > UI > Apply Key Binding
  • Ultimate Starter Kit > UI > Is Waiting For Key Press

C++ Usage

Before you can use the plugin, you first need to enable the plugin in your Build.cs file:

PublicDependencyModuleNames.Add("USK");

The MenuItem can now be used in any of your C++ files:

#include "USK/Widgets/MenuItem.h"

void ATestActor::Test()
{
    // MenuItem is a pointer to the UMenuItem
    MenuItem->SetText(Text);
    MenuItem->SetTitle(Text);
    MenuItem->SetHighlightedState(IsHighlighted, PlayHighlightedAnimation, PlayHighlightedSound);
    bool IsHighlightedValue = MenuItem->IsHighlighted();
    int Value = MenuItem->GetValue();
    MenuItem->UpdateValue(Increment);
    MenuItem->SelectItem();
    MenuItem->SaveSettings();
    MenuItem->ApplySettings();
    FKey InputActionKey = MenuItem->GetInputActionKey();
    bool OnMenuBackValue = MenuItem->OnMenuBack();
    MenuItem->AnyKeyPressed(Key);
    MenuItem->ApplyKeyBinding();
    bool IsWaitingForKeyPressValue = MenuItem->IsWaitingForKeyPress();
}