Book Image

Unreal Engine 4 Scripting with C++ Cookbook

By : William Sherif, Stephen Whittle
Book Image

Unreal Engine 4 Scripting with C++ Cookbook

By: William Sherif, Stephen Whittle

Overview of this book

Unreal Engine 4 (UE4) is a complete suite of game development tools made by game developers, for game developers. With more than 100 practical recipes, this book is a guide showcasing techniques to use the power of C++ scripting while developing games with UE4. It will start with adding and editing C++ classes from within the Unreal Editor. It will delve into one of Unreal's primary strengths, the ability for designers to customize programmer-developed actors and components. It will help you understand the benefits of when and how to use C++ as the scripting tool. With a blend of task-oriented recipes, this book will provide actionable information about scripting games with UE4, and manipulating the game and the development environment using C++. Towards the end of the book, you will be empowered to become a top-notch developer with Unreal Engine 4 using C++ as the scripting language.
Table of Contents (19 chapters)
Unreal Engine 4 Scripting with C++ Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Unreal Engine 4 (UE4) is a complete suite of game development tools made by game developers for game developers. With more than 80 practical recipes, this book is a guide that showcases techniques to use the power of C++ scripting while developing games with UE4. We will start by adding and editing C++ classes from within the Unreal Editor. Then we will delve into one of Unreal's primary strengths—the ability for designers to customize programmer-developed actors and components. This will help you understand the benefits of when and how to use C++ as a scripting tool. With a blend of task-oriented recipes, this book will provide actionable information about scripting games with UE4 and manipulating the game and the development environment using C++. Toward the end of this book, you will be empowered to become a top-notch developer with UE4 using C++ as the scripting language.

What this book covers

Chapter 1, UE4 Development Tools, outlines basic recipes to get you started with UE4 game development and the basic tools used to create the code that makes your game.

Chapter 2, Creating Classes, focuses on how to create C++ classes and structs that integrate well with the UE4 Blueprints Editor. These classes will be graduated versions of regular C++ classes called UCLASSES.

Chapter 3, Memory Management and Smart Pointers, takes the reader through using all three types of pointer and mentions some common pitfalls regarding automatic garbage collection. This chapter also shows readers how to use Visual Studio or XCode to interpret crashes or confirm that the functionality is implemented correctly.

Chapter 4, Actors and Components, deals with creating custom actors and components, what purpose each serves, and how they work together.

Chapter 5, Handling Events and Delegates, describes delegates, events, and event handlers, and guides you through creating their own implementations.

Chapter 6, Input and Collision, shows how to connect user input to C++ functions and how to handle collisions in C++ from UE4. It will also provide default handling of game events such as user input and collision, allowing designers to override when necessary, using Blueprint.

Chapter 7, Communication between Classes and Interfaces, shows you how to write your own UInterfaces, and demonstrates how to take advantage of them within C++ to minimize class coupling and help keep your code clean.

Chapter 8, Integrating C++ and the Unreal Editor, shows you how to customize the editor by creating custom Blueprint and animation nodes from scratch. We will also implement custom editor windows and custom detail panels to inspect types created by users.

Chapter 9, User Interfaces – UI and UMG, demonstrates that displaying feedback to the player is one of the most important elements within game design, and this will usually involve some sort of HUD, or at least menus, within your game.

Chapter 10, AI for Controlling NPCs, covers recipes to control your NPC characters with a bit of Artificial Intelligence (AI).

Chapter 11, Custom Materials and Shaders, talks about creating custom materials and audio graph nodes used in the UE4 editor.

Chapter 12, Working with UE4 APIs, explains that the application programming interface (API) is the way in which you, as the programmer, can instruct the engine (and so the PC) on what to do. Each module has an API for it. To use an API, there is a very important linkage step where you must list all APIs that you will use in your build in ProjectName.Build.cs file.

What you need for this book

Creating a game is an elaborate task that will require a combination of assets and code. To create assets and code, we'll need some pretty advanced tools, including art tools, sound tools, level-editing tools, and code-editing tools. Assets include any visual artwork (2D sprites, 3D models), audio (music and sound effects), and game levels. To perform that, we'll set up a C++ coding environment to build our UE4 applications. We'll download Visual Studio 2015, install it, and set it up for UE4 C++ coding. (Visual Studio is an essential package for code editing when editing the C++ code for your UE4 game.)

Who this book is for

This book is intended for game developers who understand the fundamentals of game design and C++ and would like to incorporate native code into the games they make with Unreal. They will be programmers who want to extend the engine or implement systems and actors that allow designers control and flexibility when building levels.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The parameters passed to the UPROPERTY() macro specify a couple of important pieces of information regarding the variable."

A block of code is set as follows:

#include<stdio.h>

int main()
{
  puts("Welcome to Visual Studio 2015 Community Edition!");
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

int intVar = 5;
float floatVar = 3.7f;
FString fstringVar = "an fstring variable";
UE_LOG(LogTemp, Warning, TEXT("Text, %d %f %s"), intVar, floatVar, *fstringVar );

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "After you select the tools you'd like to add on to Visual Studio, click the Next button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Unreal-Engine-4-Scripting-with-CPlusPlus-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/UnrealEngine4ScriptingwithC_Cookbook_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.