UE5 [UMG] - Simple Menu UI v3 study notes

Case address: https://www.unrealengine.com/marketplace/zh-CN/product/simple-menu-ui
insert image description here
This Demo is simple and has a basic structure, which can be used to start learning

1. UE5 entrance


1) First check Project-Maps&Modes, and find the default startup Map, GameMode and GameInstance; in addition, the Input settings also need to be checked.

insert image description here

2) When the UE5 program starts, GameInstance, GameMode and default Map are started by default;
  • Then, the LevelBlueprint program in the Map will run by default; and in the WorldSettings of the Map, the bound Pawn, HUD, PlayerController... will also be called to run.
  • In addition, the GameMode program will start and run the bound Pawn, HUD, PlayerController... (generally choose a place in Map or GameMode to bind).
  • There are 2 entrances to SimpleMenuUIv3, LevelBlueprint of Level_MainMenu, and Blueprint_GameInstance;

Description of GameInstance, GameMode, PlayerController:

  • GameInstance is to set global variables or functions, across all GameMode, etc., understood as the highest level;
  • GameMode is to set a variable or function in a certain Map or a certain game mode, and cross-domain all character scripts in this mode;
  • PlayerController is a character script, because the protagonist of the game is very important, and based on object-oriented thinking. In scripts like these, there are often many functions and variables of this object.
  • GameInstance->GameMode->PlayerController forms a layer-by-layer management structure.

Summarize:

  • UE5 entrance needs to check GameInstance (custom), GameMode (custom), LevelBlueprint, and find custom Pawn, HUD, PlayerController, etc.;
  • The programming thinking of UE5 is object-oriented thinking, and other Actor objects generally wait for the entry program call or other event calls.

2. Blueprint starts LevelBlueprint


insert image description here

  • The case writes the operation of UMG in GameInstance, where GameInstance is obtained, and two events of LoadSettings and ShowOpeningWidget are started.

3. Global blueprint Blueprint_GameInstance - UI Open (UI open/start)


1) Several key points to open the UI: determine whether to build a Widget, Create Widget to create a UI, AddToViewport to add a viewport, Show Mouse Cursor to set whether the mouse is displayed, Set Input Mode... to set the input mode.
2) Show Opening Widget opens the home page

insert image description here

  • Determine whether to display the Start standby page or the MainMenu main menu page according to the Bool value
3) Show Start Screen to open the standby page

insert image description here

  • If StartScreen is empty, Create Widget and save, -> Add to Viewport -> Show Mouse Cursor -> set bool value; these steps are UMG's routine operations
  • bool value to change whether to enter the StartScreen standby page after pressing Enter, or directly enter the MainMenu main menu page
4) Show Main Menu Display the main menu page

insert image description here

  • There are 3 types of Set Input Mode, UI Only, Game Only, and Game And UI; correspondingly, it can only control the UI interface, only control the game interface, or both can be controlled.

4. Start page Widget_StartScreen


  • Start the standby page, press enter to enter the menu page
    insert image description here
  • Widget Graph
    insert image description here
    insert image description here
1)Animation :
  • Play the UI animation, the FadeLoop breathing light animation is set in the Widget, you can use the animation control for debugging
    insert image description here
  • It needs to be added to the Graph to play:
    insert image description here
2) Input Action: Press Enter to provide the corresponding

insert image description here

  • Listen for Input Action is an input response prepared for UMG. It can also be implemented with InputAction Enter for testing, but this node provides more functions. The Consume Bool value can control whether the Callback is valid.
    The following response Enter is valid
    insert image description here
3) Parent class: BaseWidget_AnimatedCanvas
  • All UI entry and exit in this case have a simple animation, so the function is abstracted into this parent class. Including Animate_Out and Animate_In 2 animations
  • How to call:
    insert image description here
  • When this Widget is created for the first time, it calls Construct of the parent class at the same time
    insert image description here
  • How to page out:
    insert image description here
  • Call the Remove Widget event of the parent node, and then call the Show Main Menu event of Instance, the Remove Widget event of the parent node:
    insert image description here
  • First play the Animate Out animation, and then after the animation completes the event callback, Remove from Parent
    Remove from Parent node: delete this widget from its parent node on the UI layer, in short, delete the page.
    The object of Create Widget will not be deleted, only Add to Viewport can be displayed.

4)Call Remove from Parent:

In Animation Finished, there is an Event Dispatchers event called "Remove from Parent"
insert image description here
Call call, which triggers the binding event. But there is no Bind found here to correspond to the Call, so it seems to have no effect. If there is such a program, it can respond to Call.
insert image description here

5. Main page Widget_MainMenu


  • main menu page
    insert image description here
1) Text binding Game Instance data
  • The page Text binds data through Bind, the data comes from Game Instance -> GameInfo -> *, the structure Struct_GameInfo
    insert image description hereinsert image description hereinsert image description here
2) WidgeClass_Button button class (prefab)
  • Buttons in MainMenu, use the WidgeClass_Button class
    insert image description hereinsert image description here

  • Create button text and 2 color variables, which are exposed in MainMenu and can be set
    insert image description here
    insert image description here

  • Button animation, create TextHover animation (zoom in), play through Play Animation Forward and Reverse (zoom in and zoom out), and set text color

  • default setting
    insert image description here

  • animation settings
    insert image description here

Trigger the Call On Click custom event through the event scheduler
insert image description here

  • Since then, the button's text and other settings, animation settings and press event interfaces are available.
3) Call On Click button click callback
  • In the Widget_MainMenu Graph, create a Game Instance variable and bind Event to On Click;
    insert image description here
  • Callback binding, Remove Widget, and then run the Show Singleplayer Menu event in the Game Instance
    insert image description here

Summary: The UI is simple to use logic, come here first, and wish everyone a smooth development~

Guess you like

Origin blog.csdn.net/qq_17523181/article/details/128679332