Reader small image

You're reading from  Game Development Projects with Unreal Engine

Product typeBook
Published inNov 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781800209220
Edition1st Edition
Languages
Tools
Right arrow
Authors (4):
Hammad Fozi
Hammad Fozi
author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

Gonçalo Marques
Gonçalo Marques
author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

David Pereira
David Pereira
author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

Devin Sherry
Devin Sherry
author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry

View More author details
Right arrow

8. User Interfaces

Overview

In this chapter, we will continue our work on the Dodgeball-based game that we have been working on in the last few chapters. We will continue this project by learning about game UIs (short for user interfaces) and some of their forms, namely menus and HUDs. By the end of this chapter, you will be able to use UMG, UE4's game UI system, to make a menu with interactable buttons, as well as a HUD that displays the player character's current health points through a progress bar.

Introduction

In the previous chapter, we learned about general-purpose utilities that allow you to properly structure and organize the code and assets in your project by using Blueprint Function Libraries, Actor Components, and Interfaces.

In this chapter, we will dive into the topic of game UIs, which is something that's present in almost every video game. The game UI is one of the main ways to show information to the player, such as how many lives they have left, how many bullets are in their weapon, which weapon they are carrying, and so on, and to allow the player to interact with the game by choosing whether to continue the game, create a new game, choose which level they want to play in, and so on. This is shown to the player mostly in the form of images and text.

User Interfaces or UIs are usually added on top of the rendering of the game, which means that they are in front of everything else you see in the game and behave as layers (you can add them on top of one...

Game UI

There are usually two different types of game UI: menus and HUDs.

Menus are UI panels that allow the player to interact with them, either by pressing a button or a key on their input device.

This can be done in the form of many different menus, including the following:

  • Main menus, where the player can choose whether to continue the game, create a new game, exit the game, and so on
  • Level select menus, where the player can choose which level to play
  • And many other options

HUDs are UI panels that are present during gameplay that give the player information that they should always know, such as how many lives they have left, which special abilities they can use, and so on.

We will be covering game UI and making both a menu and a HUD for our game in this chapter.

Note

We won't be covering diegetic UI here, as it is beyond the scope of this book.

So how do we go about creating a game UI in UE4? The main way to do that is by...

UMG Basics

In UE4, the main way to create a game UI is by using the UMG tool. This tool will allow you to make a game UI in the form of Widgets, which can be created using UMG. It will allow you to easily edit your game UI in a visual manner, through UMG's Designer tab, while also allowing you to add functionality to your game UI through UMG's Graph tab.

Widgets are the way UE4 allows you to represent a game UI. Widgets can be basic UI elements such as Buttons, Text elements, and Images, but they can also be combined to create more complex and complete Widgets, such as menus and HUDs, which is exactly what we will be doing in this chapter.

Let's create our first Widget in UE4 using the UMG tool in the next exercise.

Exercise 8.01: Creating a Widget Blueprint

In this exercise, we will be creating our first Widget Blueprint, as well as learning the basic elements of UMG and how we can use them to create a game UI.

The following steps will help you complete...

Anchors

As you might be aware, video games are played on many different screen sizes with many different resolutions. Because of that, it is important to make sure that the menus you create can adapt to all these different resolutions effectively. This is the main purpose of Anchors.

Anchors allow you to specify how you want a UI element's size to adapt as the screen resolution changes by specifying the proportion of the screen you want it to occupy. Using Anchors, you can have a UI element always at the top left of the screen, or always occupying half of the screen, no matter the size and resolution of that screen.

As the size of the screen or resolution changes, your Widget will scale and move relative to its Anchor. Only elements that are direct children of a Canvas Panel can have an Anchor, which you can visualize through the Anchor Medallion, a white flower-like shape in the Designer tab, when you select said element:

Figure 8.10: The Anchor Medallion...

Progress Bars

One of the ways that video games can represent character stats such as health, stamina, and so on is through Progress Bars, which are what we'll use to communicate to the player how much health their character has. Progress Bars are essentially a shape, usually rectangular, that can be filled and emptied in order to show the player how a specific stat is progressing. If you want to show the player that their character's health is only half its maximum value, you could do this by showing the Progress Bar as half full. This is exactly what we'll be doing in this section. This Progress Bar will be the only element in our Dodgeball game's HUD.

In order to create this Health Bar, we'll first need to create our HUD Widget. Open the editor, go to the ThirdPersonCPP -> Blueprints directory inside the Content Browser, and right-click and create a new Widget Blueprint class of the User Interface category. Name this new Widget Blueprint BP_HUDWidget...

Summary

With this chapter concluded, you have now learned how to make a game UI in UE4, understanding things such as menus and HUDs. You've seen how to manipulate a Widget Blueprint's UI elements, including Buttons, Text elements, and Progress Bars; work with Anchors effectively, which is instrumental in allowing your game UI to adapt elegantly to multiple screens; listen to mouse events in C++, such as the OnClick event, and use that to create your own game logic; as well as how to add the Widgets you create to the screen, either at specific events or have them present at all times.

In the next chapter, we'll be taking a look at polishing our Dodgeball game by adding audiovisual elements such as sound and particle effects, as well as making a new level.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Game Development Projects with Unreal Engine
Published in: Nov 2020Publisher: PacktISBN-13: 9781800209220
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (4)

author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry