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

7. UE4 Utilities

Overview

This chapter will resume work on the dodgeball-based game that we started making in the previous chapters. We will continue with the dodgeball game by learning about a helpful set of utilities that you can implement in UE4 in order to improve the quality of your project's structure and reuse logic from it in other projects. We will specifically be talking about Blueprint Function Libraries, Actor Components, and Interfaces. By the end of this chapter, you will be able to use these utilities and other tools in your projects.

Introduction

In the previous chapter, we learned about the remaining collision-related concepts in UE4, such as collision events, object types, physics simulation, and collision components. We learned how to have objects collide against one another, changing their responses to different collision channels, as well as how to create our own collision presets and spawn actors and use timers.

In this chapter, we will go into several UE4 utilities that will allow you to easily move logic from one project to another and to keep your project well structured and organized, which will make life much easier for you in the long run and also make it easier for other people in your team to understand your work and modify it in the future. Game development is a tremendously hard task and is rarely done individually, but rather in teams, so it's important to take these things into account when building your projects.

We will mainly be talking about Blueprint Function Libraries, Actor Components...

Blueprint Function Libraries

In UE4, there's a class called BlueprintFunctionLibary, which is meant to contain a collection of static functions that don't really belong to any specific actor and can be used in multiple parts of your project.

For instance, some of the objects that we used previously, such as the GameplayStatics object and Kismet libraries such as KismetMathLibrary and KismetSystemLibrary, are Blueprint Function Libraries. These contain functions that can be used in any part of your project.

There is at least one function in our project created by us that can be moved to a Blueprint Function library: the CanSeeActor function defined in the EnemyCharacter class.

Let's then, in the first exercise of this chapter, create our own Blueprint Function library, so that we can then move the CanSeeActor function from the EnemyCharacter class to the Blueprint Function library class.

Exercise 7.01: Moving the CanSeeActor Function to the Blueprint Function...

Actor Components

As we've seen in the first chapters of this book, Actors are the main way to create logic in UE4. However, we've also seen that Actors can contain several Actor Components.

Actor Components are objects that can be added to an Actor and can have multiple types of functionality, such as being responsible for a character's inventory or making a character fly. Actor Components must always belong to and live inside an Actor, which is referred to as their Owner.

There are several different types of existing Actor Components. Some of these are listed here:

  • Code-only Actor Components, which act as their own class inside of an actor. They have their own properties and functions and can both interact with the Actor they belong to and be interacted with by it.
  • Mesh Components, which are used to draw several types of Mesh objects (Static Meshes, Skeletal Meshes, and so on).
  • Collision Components, used to receive and generate collision...

Interfaces

There's a chance that you might already know about Interfaces, given that other programming languages, such as Java, for instance, already have them. If you do, they work pretty similarly in UE4, but if you don't, let's see how they work, taking the example of the Health Component we created.

As you've seen in the previous exercise, when the Health property of the Health Component reaches 0, that component will simply end the game. However, we don't want that to happen every time an actor's health points run out: some actors might simply be destroyed, some might notify another actor that they have run out of health points, and so on. We want each actor to be able to determine what happens to them when they run out of health points. But how can we handle this?

Ideally, we would simply call a specific function that belongs to the Owner of the Health Component, which would then choose how to handle the fact that the Owner has run out of health...

Blueprint Native Events

When using the UFUNCTION macro in C++, you can turn a function into a Blueprint Native Event by simply adding the BlueprintNativeEvent tag to that macro.

So what is a Blueprint Native Event? It's an event that is declared in C++ that can have a default behavior, which is also defined in C++, but that can be overridden in Blueprint. You declare a Blueprint Native Event called MyEvent by declaring a MyEvent function using the UFUNCTION macro with the BlueprintNativeEvent tag, followed by the virtual MyEvent_Implementation function:

UFUNCTION(BlueprintNativeEvent)
void MyEvent();
virtual void MyEvent_Implementation();

The reason why you have to declare these two functions is that the first one is the Blueprint signature, which allows you to override the event in Blueprint, while the second one is the C++ signature, which allows you to override the event in C++.

The C++ signature is simply the name of the event followed by _Implementation, and...

Summary

You now know about several utilities that will help you to keep your projects more organized and allow better reuse of the things that you make.

You have learned how to: create a Blueprint Function Library; create your own Actor Components and use them to refactor the existing logic in your project; and create Interfaces and call functions from an object that implements a specific Interface. Altogether, these new topics will allow you to refactor and reuse all the code that you write in a project in that same project, or in another project.

In the next chapter, we'll be taking a look at UMG, UE4's system for creating user Interfaces, and learning how to create our own user Interfaces.

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 €14.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