New Project -> Blueprint -> First Person
.Create Project
.Play
, if you are wondering what the FPS game template is.Content Browser
open the Maps
folderLevel
item.MainMenu
call the new level MainMenu
.Content Browser
return to the level above and through the same context menu create a New Folder
, call it UI
.UI
folder, create a new widget through the context menu: Widget Blueprint
MainMenu
. Open the widget by double clicking and see the next screen. By default, it opens in a new window, but you can drag a tab into the main window or simply expand it to full screen.Palette
on the left, drag a Text
element onto the main field and enter some string into it. To automatically set the size of the element in accordance with the text, check the Size To Content
option.Details
panel, the Position X Y
options determine the position of the element relative to the anchor point (the “Chamomiles” center) and are calculated according to the values of the Alignment
option, which specifies the point of the element itself in values from 0.0
to 1.0
.X 0.5 Y 0.0
sets the point in the middle of the element horizontally and on the upper border of the element vertically.Anchors
option.Details
panel, set the font size to a larger one, for example, 60 units.Vertical Box
element - it allows you to automatically align several child elements; in our case, these will be buttons.Vertical Box
can be found in the Palette
panel, in the Panel
section.Vertical Box
place the Button
element, and inside the Button
, place the Text
element. On the left, in the Hierarchy
, you can verify that everything is located correctly. If not, then there you can move the elements to get the desired nesting.float
(RGBA: red, green, blue, alpha), each value can be from 0.0
to 1.0
.alpha
value to zero in the Background color parameter. Do not forget to select the button, and not the text element inside it.
".Hierarchy
panel, call the context menu on the Button
element, select the Copy
item (or press Ctrl+C
/ ⌘+C
), then select the Vertical Box
and paste the copied button 3 times.
", "
", "
." The latter is illogical and should be placed at the very top. To do this, select the button and use the navigation buttons that we have thanks to the Vertical Box
.MainMenu
level.Blueprints
button and in the menu that appears, select Open Level Blueprint
. The blueprint editor will open, where you can create handlers for various events and generally write the logic of the game (not specifically in the level blueprint, but in the same interface).BeginPlay
nodes, then add it via the context menu and search string. The location of the node on the field does not matter, but in the case of complex scripts, it is better to try to locate the node immediately so that you do not get confused later.BeginPlay
create next to the Create Widget
node:Create Widget
node when the BeginPlay
event BeginPlay
, connect the outgoing exec-pin of the BeginPlay
node with the incoming exec-pin of the Create Widget
node. To do this, left-click on the pin and without releasing the button drag to the incoming pin.Create Widget
node, in the Class
parameter, select our MainMenu
widgetOwning Player
draw a line to an empty place (yes, this is also possible), release and look for the Get Player Controller
node in the menu, add it. Since UE4 is a multiplayer engine, this parameter determines which player will be shown the widget. In the case of a single player, you can simply leave the Player Index
equal to zero.Return Value
Create Main Menu Widget
node, drag the connection to an empty place and look for the Add to Viewport
node in the menu. In this case, when creating a node, an exec-connection should connect automatically.ZOrder
option - it sets the order in which the widgets will be superimposed on each other if we add several widgets to the screen at once. For the menu, it will be logical to put a larger value so that the menu is always on top of the other widgets. For example, 9999
.Set Input Mode UI Only
node. As the Target
parameter Target
you need to specify the same Player Controller
as before, and as the widget, the object created by the Create Widget
node.Compile
button. Go back to the main tab, save everything (menu File -> Save All
) and press the big Play
button in the toolbar!Stop
(or just Esc
on the keyboard).Main Menu - Level Blueprint
tab Main Menu - Level Blueprint
.Get Player Controller
node, we pull out the connector and create a new Set Show Mouse Cursor
node.Show Mouse Cursor
parameter (dark red of the pin is Boolean
; setting the tick equals setting the value to true
, unchecking the tick is false
). We connect the node between BeginPlay
and Create Main Menu Widget
and move the nodes so that they do not get confused.Compile
again and return to the main tab. Click Play
.MainMenu
widget. If you have closed or lost it - you can always open it again by double-clicking on the necessary asset in the Content Browser
panel.
” and “
”. And the other buttons, for now, turn off.
" button (it is more convenient to do this in the Hierarchy
panel to select the button itself, rather than the text element) and on the right in the Details
panel we find the Is Enabled
option. In order not to dig into a bunch of parameters, you can always use the search bar at the top just enter " enabled
". Uncheck it.
" button.Button
'ah. To do this, in the Hierarchy panel, select the desired item and click on it once, or select Rename in the context menu. I renamed the buttons to ButtonContinue
, ButtonStart
, ButtonOptions
and ButtonExit
respectively.ButtonStart
and scroll the Details
panel down to the Events
section. There will be some green buttons.OnClicked
button and get into the blueprint of our widget with the newly created On Clicked (ButtonStart)
event On Clicked (ButtonStart)
. Create an Open Level
node, connect it to the event, and specify the " FirstPersonExampleMap
" parameter in the Level Name
(the name of the default level can be viewed in the Content Browser
).UI Only
. Now we need to do the opposite - switch to Game Only
.Set Input Mode Game Only
node. At the same time, the Open Level
node will automatically reconnect to the new node; you will only need to align them. Well, let's not forget that you need to specify the Target
parameter in the new node - connect the Get Player Controller
node there.Compile
and Save
, launch, click "
" ... Hooray, we are in the game!ButtonExit
handler ButtonExit
left for homework - it is even simpler: you just need to use the Quit Game
node with the default parameters. To return from the blueprint of the widget to return to the UI editor, you can use the switch at the top right.Source: https://habr.com/ru/post/334426/
All Articles