Unreal Engine 4.X By Example - Benjamin Carnall - E-Book

Unreal Engine 4.X By Example E-Book

Benjamin Carnall

0,0
41,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

An example-based practical guide to get you up and running with Unreal Engine 4.X

About This Book

  • A unique resource on Unreal with an interactive example based approach that is sure to get you up and running immediately
  • Will feature four unique game projects that increase in complexity which will enable readers to build their game development skills using Unreal Engine 4 and the C++ programming language
  • Will be the most up to date book in the market on Unreal with full coverage of the new features of UE4

Who This Book Is For

Unreal Engine 4.X by Example was written for keen developers who wish to learn how to fully utilise Unreal Engine 4 to make awesome and engrossing game titles. Whether you are brand new to game development or a seasoned expert, you will be able to make use of the engine with C++. Experience with both C++ and other game engines is preferred before embarking on the Unreal by Example journey, but with a little external research into the basics of C++ programming, this book can take a complete game development novice to an Unreal Engine Developer!

What You Will Learn

  • Use C++ with Unreal Engine to boost the development potential of any Unreal Engine project
  • Vastly improve workflow and content creation with the visual scripting system blueprint
  • Design, test, and implement interesting game worlds using Unreal Engines built-in editor
  • Build a networked, feature-rich first person shooter that you can play with others over LAN
  • Build design-centric game worlds that play to needs of your game ideas
  • Paint your game worlds via the creation and modification of visual shaders called materials
  • Gain knowledge of other game development disciplines through the use of the Animation and Material tool sets
  • Create feature-rich game projects with a sophisticated visual quality and feature set

In Detail

With Unreal Engine 4 being made free to use, for any keen game developer it is quickly becoming the most popular game engine in today's development industry. The engine offers a rich feature set that can be customized and built upon through the use of C++. This book will cover how to work with Unreal Engine's tool set all the way from the basics of the editor and the visual scripting system blueprint to the in-depth low-level creation of content using C++.

This book will provide you with the skills you need to create feature-rich, captivating, and refined game titles with Unreal Engine 4. This book will take you through the creation of four unique game projects, designed so that you will be ready to apply the engine's rich development capabilities. You will learn not only to take advantage of the visual tools of the engine, but also the vast and powerful programming feature set of Unreal Engine 4.

Style and approach

The best resource that any beginner level game developer can dream of with examples on leveraging the amazing graphics engine, beautiful character animation and game world generations etc. by means of exciting real world game generation.This book would be a very unique resource for any game developer who wants to get up and running with Unreal. The unique example-driven approach will take you through the most basic games towards the more complex ones and will gradually build your skill level.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 688

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Unreal Engine 4.X By Example
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introduction to Unreal Engine 4
Navigating this book
Game Projects you say?
Installing Unreal Engine 4
Creating your first project!
Navigating the Unreal Engine UI
Creating a basic actor
Objects, Actors, Pawns, and Characters
Adding components to your Actor
The component hierarchy
Modifying components
3D transformation and axis
Adding the Unreal factor
Pre-Built projects as a learning resource
Summary
2. Blueprints and Barrels – Your First Game
Creating your first Blueprint
The Blueprint window
Working with Blueprints
Blueprint elements
Graphs
Functions
Macros
Variables
Event dispatchers
Modifying the Hello Sphere Blueprint
Working with Blueprint graphs
Compiling Blueprints
Using Blueprint variables
Utilizing the Blueprint palette
Blueprint meta-data and string manipulation
Creating the Barrel Hopper project!
Creating our Character
Bringing our character to life
Giving our character a mesh
Creating the character's camera
Game modes and how to make them
Creating and receiving input events
Creating the input Events
Receiving input events
Tweaking the character movement component
Building the level!
Camera tips and tricks
Camera settings
Controlling the camera
Creating the level
Blocking geometry
Geometry Brushes and how to use them
Placing the geometry
Converting a geometry Brush to a static mesh
Applying materials to geometry brushes
Level building and trigonometry!
Getting our barrels rolling
Applying physics to objects
Barrel spawners and Blueprint timers
Creating Blueprint variables
Event tick
Branch nodes
Trigger volumes and destroying Actors
Debugging our Blueprints
Masking our destruction with particles
Respawning the player
Delay nodes
Player controllers
Hit Events
Summary
3. Advanced Blueprint, Animation, and Sound
Cleaning up shop
Logic flow
Using a sequence
Creating custom cameras
Where do we spawn the camera?
Spawning the camera object
Setting the Target View
Respawning the player with a Blueprint function
Creating the Blueprint function
Animation with UE4
Animation Conventions
Animation Blueprints
Importing and exporting animation assets
Creating your first animation Blueprint
Navigating animation Blueprints
The toolbar
Populating the Animation graph
Working with state machines
State nodes
Transition Rules
Playing animations from within states
Finishing our state machine
The Animation Blueprint Event graph
Getting our character running
Working with Blendspaces
Creating the running Blendspace
Utilizing the running Blendspace
Creating your first sound scape
Importing sounds and sound cues
Working with sound cues
Sound modification
Playing sounds via animation notifications
Working with animation assets
Notifies
Curves
Additive layers
Statistics bar
Placing the animation notifies
Finishing our soundscape
Exploding barrels
Players death rattle
Looping level sound
Adding the finishing touches to Barrel Hopper
Ragdolls and Event dispatchers
Creating a basic HUD
Making the HUD object
Drawing the in game HUD
Making the font
Parsing information to and setting the HUD
An end goal for the player, the chapter, and the project
Summary
4. Unreal Engine, C++, and You
UE and C++
Why use C++
Polymorphism, virtual inheritance and templates
Hello World for C++
Exploring your first code class
Accommodating for the Unreal Build Tool
Pre-Compile macros and you
Breaking down the rest of the header file
The default constructor and include list
Virtual functions and calling the parent
Adding components and object creators
Construction helpers and object finders
Building the code
Adding Fire Particles and Hot Compilation
Setting the sphere on fire
Hot Compilation
Hello world text and receiving events through delegates
Adding the 3D text
Delegates and Events
Polishing the sphere
Changing materials via C++
Extending C++ into Blueprint
Extending a class with no macro specifier support
Extending a class with macro specifier support
Defining a class with macro specifiers
Working with code created components
Blueprint native events and you!
Overriding a BlueprintNativeEvent
Summary
5. Upgrade Activated – Making Bounty Dash with C++
Creating a C++ character
Create the C++ project
The UE4 object hierarchy
Creating the Character
What we have been given
What we are going to need
BountyDashCharacter's members
BountyDashCharacters methods
Constructing the Character
Borrowing from the old to make the new
Assigning Blueprints in code with generated classes
Setting up the components
Assuming default control
Writing the begin Play function
Getting In-Editor objects using the Game World
Sorting TArrays with Lambdas
Setting up inputs in C++
Binding actions
How our Character is going to Tick
Compile time
Creating the C++ world objects
Converting BSP brushes to a static mesh
Smoke and mirrors with C++ objects
Modifying the BountyDashGameMode
BountyDashGameMode class definition
BountyDashGameMode function definitions
Getting our game mode via Template functions

Coding the floor
Floor class definition
Floor function definitions
AFloor::AFloor() constructor
AFloor::Tick()
Placing the Floor in the level!
Creating the obstacles
Spawning actors from C++!
Obstacle Spawner class definition
Obstacle Spawner function definitions
Getting information from components in C++
Ensuring the Obstacle Spawner works
Minting the coin object
Coin class definition
Coin function definitons
Making the coin Blueprint!
Making it rain coins, creating the coin spawner
Coin Spawner class Definition
Coin Spawner function definitions
Testing what we have so far!
Creating the interactions between the world objects
Pushing the Character
ABountyDashCharacter Collision functions
Pushing the character back
Picking up coins
Coin collision
Summary
6. Power Ups for Your Character, Power Ups for the User
Cleaning up shop and object hierarchies
BountyDashObject
Modifying existing objects
Creating a Plug-in with C++
Modules and code files
The anatomy of a plugin
Describing a plugin
PowerUpPlugin.uplugin
Working with our first plugin module
PowerUpPlugin.Build.cs
Declaring the PowerUpPlugin code module
Adding the PowerUp object
Using our plugin in engine
Creating the BountyDashPowerUp object
Incorporating power-ups into Bounty Dash
Modifying the Coin Spawner
Build, run, and test!
Colliding with power ups
Powering up the character
Reducing the game speed
Making the coin magnet
How to create, load and smash Destructible Meshes
Creating HUDs using C++
ABountyDashHUD
Getting information from our objects
Setting the HUD class in the game mode
Implementing a custom DrawHUD function
Completing the Bounty Dash game loop!
The beginning of the end and pausing the game
Pausing the Game
Restarting the game
Drawing the game over text
Finishing the wall of death and polishing the project
Making the wall of death
Making the new floor mesh
ADestroyedFloorPiece
Modifying the AFloor object
Bells, whistles and explosions
Playing sound from C++
Playing particles from C++
Getting the character to run
The last bit of concealer
Summary
7. Boss Mode Activated – Unreal Robots
Setting up the project
The first-person character
Importing what we need
Beginning the FPC
Establishing a FPC aim/movement
Defining the FPC constructor
Defining the FPC move and aim functions
Creating the input bindings
Binding the inputs
Abstracting a BM character into Blueprint
Setting a Blueprint object as the default pawn in a C++ game mode
Testing what we have!
Adding a custom HUD and drawing a cross hair
BMHUD class definition
Defining the BMHUD
Creating the projectile
Defining the Projectile
Initializing the Projectile
Colliding with the Projectile
Subclass templates and firing the projectile
Modifying BMCharacter accommodate for the projectile
Creating the FPProjectile Blueprint
Modifying FPCharacter
Unreal Robots
AI breakdown
Preparing your project for AI intergration
Creating the AI character base class
Creating your first AI controller
Behavior tree breakdown and logic flow
What are blackboards?
Creating a basic behavior tree and black-board!
Setting up the blackboard
The behavior tree Editor
Setting up the behavior Tree
Creating a custom task via blueprint
Creating a custom decorator using blueprint
Creating a custom service using C++
Defining the BMArgoCheck class
Advanced collision in UE4
Defining the service tick
Adding the C++ service to the BossBT
Integrating the AI Character
Creating a custom object collision channel
Modifying the level to support AI
What is a navigation mesh
Adjusting the NavMesh generation settings
Placing a NavMesh in the scene
Placing the AI in the level and testing
Summary
8. Advanced AI and Unreal Rendering
Expanded AI and tracking projectiles
Tracking projectiles and you
Creating the line trace
Preparing the projectile
Creating the custom channel and testing the tracking!
Expanded AI
Damage in UE4
Boss state and enums in blackboard!
Interpreting our C++ enum in Blackboard
Modifying the BossBT to support Boss States
Debugging BossBT to check Blackboard values
Upgrading the ABMIController
Tracking to the player
Testing what we have so far
Arming the boss
Adding the Turret boss state
The Final Behaviour State
BMRandomMoveTo
Finishing the BossBT
AI Complete
Rendering in UE4
UE4 Materials
What are materials
Physically Based Rendering
The Material editor
The Toolbar
The Viewport
The Graph and Base material node
The Details panel
The stats panel
The Palette
Starting the Boss outer material
Your first material expression and color channels
Applying a Normal Map and the texture viewer
Emissive color and masks
Adding more detail and advanced material use
Texture UV's and adding normals
Functions of time within materials and pulsing glow
Making the Boss inner material
Setting up what we know
Masking values based on UV
Applying the material to the Boss
Summary
9. Creating a Networked Shooter
Creating the project
Adding a marketplace package
Network multiplayer theory
Networking patterns
Peer to Peer (P2P)
Client/server
UE4 Networking
Dedicated or listen servers
UE4 replication
Network role
Remote Procedure Calls (RPCs)
Types of RPC
Defining RPCs
Net ownership, player controllers and game modes
Starting the networked First Person Shooter
Preparing the NS project
Making a networked player character
NSCharacter visual and audio assets
Player states and networking
Finishing the Player class definition
Writing the ANSCharacter RPCs
Defining the ANSCharacter functions
Dynamic materials and material parameters
Getting the player to shoot… online
Taking damage and UE4 timers
Cleaning up shop
Preparing the ANSCharacter blueprint
Preparing the third-person Mesh
Creating the force feedback asset
Custom collision channel
Highlighting the VectorParameter that drives team color
Making the fire montage assets
Tying it all together
Testing the multiplayer with a PIE session!
Spawn points and spawning the players
Defining the ANSSpawnPoint class
ANSSpawnPoint function definitions
Game modes and servers
Game mode class definition
Construction the Game mode and Finding Spawn points
Ending the Game and ticking the game mode
Connecting players
Spawning the players
Respawning the player
Preparing our game map
Testing our game functionality
Drawing the HUD and preparing the lobby
Creating the GameState
Drawing in the HUD
Testing our Game
Summary
10. Goodbyes and Thank yous
Packaging a project
Build Targets
Build configuration
Compiler specific building to configuration
Packaging NS
Testing the NS package
Creating the listen server instance
Console commands
Connecting to the local host
Profiling using the console commands
Console visualizations
Wrapping up the NS project
What we have learned so far
The Editors
Blueprints
Unreal animation
C++
Artificial Intelligence
Unreal Rendering
Unreal networking!
Summary
Index

Unreal Engine 4.X By Example

Unreal Engine 4.X By Example

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: July 2016

Production reference: 1260716

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-553-2

www.packtpub.com

Credits

Author

Benjamin Carnall

Reviewer

Matt Matte

Commissioning Editor

Amarabha Banerjee

Acquisition Editor

Reshma Raman

Content Development Editor

Parshva Sheth

Technical Editor

Gebin George

Copy Editor

Joanna McMahon

Project Coordinator

Ritika Manoj

Proofreader

Safis Editing

Indexer

Tejal Daruwale Soni

Graphics

Abhinash Sahu

Production Coordinator

Aparna Bhagat

About the Author

Benjamin Carnall is an enthusiastic and dedicated programmer whose love for problem solving led him to the world of game development. He relishes opportunities to learn new and interesting ways to create gameplay experiences for others. Ben began his journey with Game Development in 2012, after he graduated from Media Design School with a diploma in interactive gaming. He then went on to graduate from the same university with a bachelors of software engineering in 2014. Since then, Ben has immersed himself in the Game Development community of New Zealand—starting out as a programming contractor and working on various titles around Auckland. He then began to work as a lecturer at Media Design School and taught Graphics programming for games, Physics programming for games, and Sony PlayStation development at the bachelors level. Most recently, Ben has been working as a programmer for the studio Aroura44, developing a title called Ashen.

I would like to thank so many people for supporting me during the authoring of this book. Thanks to the wonderful people around me, I remained fed and happy while endeavoring to put into words the jumble of information that knocks around in my head.

Thank you to my parents for making sure I stayed healthy and well fed. Thank you to my lovely Emily, for keeping my morals high and my smile wide. Thanks to the team at Epic for making such an awesome engine! Without them I would not be writing this now. Thanks to my editor, Parshva Sheth, for working through this with me, we made it! And finally, I'd like to thank you, the reader, for taking a chance with this book and for jumping into the world of game development!

About the Reviewer

Matt Matte is the founder of Full Metal Jacket Games, and he was recently featured on Unreal Engine's Spotlight Projects section with their Tron- inspired VR game. Matt is the official Seattle Unreal Engine Rep and the organizer of the largest Unreal Engine Meetup in the world, with over 800 members. He's published three games with Unreal Engine. The latest game released in August 2016 is Monkey Land 3D: Reaper Rush.

Matt has over 10 years of experience in Unreal Engine, starting with building mods in the Unreal Engine 3 editor and then moving on to UDK and UE4 to build completely original titles. He's an expert Unreal developer and technical artist that specializes in setting up characters, both controlled by a player and Artificial Intelligence, including rigging and creating animations, setting up physics with the PHAT editor, animation blueprints, and blending, AI behavior trees, and synchronized special effects. He's created games with Blueprints only and a hybrid of both C++ and Blueprints.

His primary focus is on virtual reality games. F.M.J. Games has won two Seattle VR Hackathons for best graphics and experience. They also won the Peoples Choice Award for NASA's 2015 Space Apps Challenge, all with UE4 and its powerful real-time rendering. They've been awarded new VR hardware by Epic, Oculus, and Valve for their accomplishments in VR design.

Matt has reviewed the blueprints and code in this book and tested that they work and are fully functional. Contact Matt through www.fmjgames.com for anything Unreal Engine game development related.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

Unreal Engine 4 is a cutting-edge game development engine that has revolutionized the way developers pay for engine licenses. Instead of forking out millions of dollars to access this first class engine, developers can use it completely free of charge, until they find themselves with a profitable product on their hands.

Unreal Engine 4 provides a rich AAA development toolset with cutting-edge technical features to anyone who is keen to develop great games. The engine has been developed in C++, and not only are we able to leverage the power of C++ for our projects, but we also have access to the entire engine source! This book will start you on your journey toward mastering UE4's toolset and becoming a proficient C++ UE4 developer!

What this book covers

Chapter 1, Introduction to Unreal Engine 4, takes you through the installation of UE4, creating new UE4 projects, and an introductory overview of the main engine editor.

Chapter 2, Blueprints and Barrels – Your First Game, introduces you to the world of Blueprint Visual Scripting. You will leverage the Blueprint system of UE4 to create your first UE4 game project, called Barrel Hopper.

Chapter 3, Advanced Blueprint, Animation, and Sound, covers some of the more advanced Blueprint concepts, and it also concludes the development of the Barrel Hopper project by showing you how to include animation and sound in your projects.

Chapter 4, Unreal Engine, C++, and You, introduces you to the concepts and syntax that will be encountered when working with C++ and Unreal Engine 4.

Chapter 5, Upgrade Activated – Making Bounty Dash with C++, will expand on your knowledge of C++ with UE4, by taking you through the development of a purely C++ implemented game project!

Chapter 6, Power Ups for Your Character, Power Ups for the User, guides you in creating a UE4 C++ plugin, and it also introduces you to some advanced UE4 C++ concepts. This chapter concludes the development of Bounty Dash!

Chapter 7, Boss Mode Activated – Unreal Robots, will introduce you to UE4's extensive AI toolset by taking you through the creation of the Boss Mode game project.

Chapter 8, Advanced AI and Unreal Rendering, covers some of the advanced concepts of UE4's AI system; it will also introduce you to UE4's material editor and rendering system!

Chapter 9, Creating a Networked Shooter, breaks down and explains all the networking systems included in UE4. This chapter will have you create your own networked First Person Shooter, which you will be able to play over LAN with your friends.

Chapter 10, Goodbyes and Thank yous, will show you how to package your project for distribution and testing, and it also covers a brief summary of what has been learned before concluding the book!

What you need for this book

Processor: Quad-core Intel or AMD, 2.5 GHz or fasterMemory: 8 GB RAMVideo Card: DirectX 11 compatible graphics card Unreal Engine 4.10.*

Who this book is for

Unreal Engine by Example was written for keen developers who wished to learn how to fully utilize Unreal Engine 4 to make awesome and engrossing game titles. Whether you are brand new to game development or a seasoned expert, you will be able to make use of this engine with C++. Experience in both C++ and other game engines is preferred before embarking on the Unreal by Example journey; but with a little external research into the basics of C++ programming, this book can make a complete game development novice into an Unreal Engine developer!

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: "It is now time for the famous Hello World."

A block of code is set as follows:

#include "BMBossCharacter.h" #include "BehaviorTree/BlackboardComponent.h" #include "BehaviorTree/BehaviorTree.h"

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: "Then create a new Blackboard asset from the same category."

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 <[email protected]>, 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:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.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 WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Unreal-Engine-4X-By-Example. 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/UnrealEngine4XByExample_ColoredImages.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 <[email protected]> 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 <[email protected]>, and we will do our best to address the problem.

Chapter 1. Introduction to Unreal Engine 4

Welcome to Unreal Engine 4 by Example! During the course of this book you are going to learn how to utilize Unreal Engine 4 (UE4) to create high-quality games using C++. This chapter will show you how to install the engine, introduce you to the engine's User Interface (UI), show you how to create new projects, and give you a rundown of what to expect from this book. The purpose of this chapter is to give you a general idea of how this book will be formatted and how to get the most out of your Unreal Engine 4 by Example experience.

The chapter will cover the following points:

Navigating this book and what to expectInstalling UE4Creating new UE4 projectsNavigating UE4's User InterfaceCreating a basic actor and adding componentsOpening and exploring the examples provided by Unreal

Navigating this book

First off, it should be stated that the use of C++ features heavily in the later stages of this book. It is strongly advised that you already have some experience with writing in C++ or a similar low-level language before embarking on this journey.

This is a By Example book, meaning that you will be taught how to use UE4 via the breakdown and explanation of previously created UE4 game projects. These projects have been created specifically for this book with your education in mind! Each project will be taught over two chapters, the first will include the core concepts and features needed to implement the title. The second will delve into the advanced or more complicated components of each project. By the end of each project you will have learnt core UE4 functionality plus some very interesting polish techniques.

By the end of this book you should find yourself well on your way to becoming a skilled Unreal Engine developer capable of using C++ and the provided Blueprint system to utilize Unreal Engine's rich feature set to create polished game titles.

Game Projects you say?

Yes, game projects! By the end of this book you will have created four unique game projects that will all include their own polish features. These projects culminate with the creation of your very own multiplayer first-person shooter!

During the course of this book you will create the following game projects:

Barrel Hopper: A homage to the original Donkey Kong, this project will be created entirely using Blueprint and will introduce you to the high-level systems used when creating games with UE4.Bounty Dash: Our take on an endless runner, this project will be your first look into C++ with UE4. We will be expanding on some of our content created for Barrel Hopper and really start to unlock the potential of UE4.Boss Mode: For this project we will be expanding on your C++ technical skill set by creating an engagement with a game boss controlled by Artificial Intelligence (AI), which will be visually detailed by taking advantage of UE4's in-depth rendering and shading functionality.Network Shooter: This will be the culmination of your journey with this book and your UE4 education. You will be creating a networked first-person shooter that lets you create a game you can play with your friends through a Local Area Network.

Installing Unreal Engine 4

The version of Unreal Engine we will be using for this book is Unreal Engine 4.11.0. You may use any 4.11.# engine version as long as your version number exists within the 4.11 family. If you have already installed Unreal Engine 4.11 you can skip this section and jump straight to Creating your first project. First things first, you need to sign up as an Unreal Engine developer. Navigate to https://www.unrealengine.com in your browser and select the GET UNREAL option located in the top right-hand corner of the web page.

This will then redirect you to the login/sign-up page for a UE account. If you do not have an account, follow the steps presented in the page to create one. This account will integrate you into the Unreal Development community. Through this account you can get Unreal Engine news, updates, and developer support.

Once this is done you will be directed to the downloads page, choose the OS that you will be developing on (MAC, Windows) and you should see the download begin for an Epic Games Launcher installer. The Epic Game Launcher is the portal for all Unreal Engine versions and you will use this application to install, manage, and launch the engine version you wish to use.

Once the Epic Games Launcher has been successfully installed, run it and it will prompt you to log in with the account credentials you previously set up with Epic. If everything has gone according to plan you should be presented with the Unreal Engine launcher. From the launcher you will need to navigate to the Unreal Engine tab located in the top left-hand side of the window. From here you can see News, Learning Resources, and Marketplace Content for the engine. I advise you to take your time to explore each of the options available to you, however we will be focusing on the Library section.

By selecting the Library element on the list on the left-hand side of the window you will be presented with any currently installed engines as well as any Unreal projects you have already created. There will be an Add Versions button near the top of the window.

Pressing this button will present you with a light-colored engine node, click the drop-down arrow next to the engine version number and be sure to select 4.11.0. Once this is done, hit Install. The launcher will now handle downloading and installing your new engine version!

While the engine is installing I would strongly suggest you spend some time exploring https://www.unrealengine.com. The website is a great place to find video tutorials, learning resources, and the Unreal Engine Wiki. You do not need to utilize these resources to follow this book, however the content they have provided is very informative and will definitely help you on your journey to becoming a proficient Unreal Engine developer. Once the engine has been installed, hit Launch and you are ready to go!

Tip

Tip: If you hit the drop-down arrow next to launch you can create a shortcut for the engine version.

Creating your first project!

It is now time for the famous Hello World, but this time it will be Hello Unreal. With your engine version launched you will be presented with the Unreal Project Browser. This browser features two tabs, Projects and New Project, select New Project. The first thing you can see in this tab is a large selection of icons under two more tabs, Blueprint and C++. We will be selecting the Blueprint tab and we will be creating a Blank project, your selection should appear as follows:

Under this section you will see three dropdown boxes titled Desktop / Console, Maximum Quality, and With Starter Content. We will leave these as they are for now but this is where you can swap your target platform for the project, change the graphics quality, and whether or not you would like to use the starter content provided by Epic. Below these options you will see fields to populate the directory where you wish to create the project and what the name of the project will be. We shall title this project Hello Unreal. Once this is done, click the green Create Project button and the engine will finally launch.

Navigating the Unreal Engine UI

Welcome to the Unreal Engine User Interface! It can be a bit overwhelming at first but, fear not, all will be explained. By the end of this book you will be very familiar with the layout and workings of this engine view. Now, for the sake of brevity, I will hand your Unreal education over to the Epic team for a short moment. In the top right-hand corner of the window next to the name of the project you should see a grey academia cap flashing green.

Clicking this cap will start a short tutorial that will familiarize you with the engine's layouts and panels. I am leaving this up to Unreal as the introductory tutorials are succinct and efficient at bringing you up to scratch with the editor layout and camera controls. This gives us more time to get to the juicy learning!

Once you have completed this introductory tutorial you will be guided to the tutorial home panel. Here you will be able to find a list of simple tutorials that will help familiarize you with the different features of the engine, could you please complete the two tutorials under the Basics category. Feel free to utilize the other tutorials during the course of the book. I will likely be covering almost all of the topics covered in the tutorials but they may prove useful as an additional learning resource. Now that Epic has taught you how to view its engine, it is now time to teach you how to use the engine!

Creating a basic actor

At this point you should have a world that looks similar to this:

What we are going to do now is remove the table, statue, and chairs from our level and replace them with our own actor. The purpose of this is to show you how we can create new actors and add components from within the editor without having to navigate to other areas of the engine. You can remove actors by clicking on them and hitting the Delete key, right-clicking on them and selecting Edit | Delete from the dropdown menu, or by finding the actor in the World Outliner and performing the same steps.

Once the table and chairs have been removed, we need to add an actor to the world that we wish to build upon. To do this we need to place an element from the Modes Panel in the top left-hand side of the window. As stated in the introductory tutorial, the Modes Panel is where you can find all of the tools that you will need to perform construction actions within the editor. The five tabs you can interact with are Place, Paint, Landscape, Foliage, and Geometry Editing.

These options will be explored during the course of this book but, for now, we are concerned with the Place tab. The Place tab is where you can find all of the editor objects that can be dragged and dropped into the level. Here you can find things such as basic geometry primitives, BSPs, visual effects, and numerous processing volumes.

Tip

If you wish to see detailed documentation for each of the editor objects, click the small question mark on the right-hand side of the object name.

From the list on the left-hand side of the panel, select Basic; this will show you a selection of simple objects that can be dragged into the world. We want to drag an Empty Actor into the world.

Objects, Actors, Pawns, and Characters

Unreal Engine utilizes a specific naming convention for the objects that can be created and built upon within the editor. There are Objects, Actors, Pawns, and Characters. Each name represents an expanded level of functionality. In general, you can think of Actors as whole items or entities such as a power up or boost pad, where an object is usually a small part or Component with specialized functionality. For example, a whole car could be an Actor but the engine within the car would be considered an Object. Pawns and Characters I will detail in later chapters. The term object(s) will be used to refer to things in our levels but when required I will use the capitalized Actor or Object when specification is required.

Select our new actor now by clicking on it within the viewport. With the Empty Actor selected in our world we are presented with a few new visual elements. The first is the transform widget; the transform widget provides us with the ability to translate, rotate, and scale objects within our world. You can swap the functionality of your transform widget by pressing the W key for translation, the E key for rotation, and the R key for scale. Alternatively, in the top right-hand side of the Viewport panel you can click and select the appropriate transform icon. We can also select the globe icon in the same corner to swap between world and local space transformation. Simply put, world space transformation will present a transform axis in line with the world. Local space will present a transform axis in line with the object (based on the objects arbitrary forward).

Tip

If you are ever curious to see the world space axis, it can be found in the bottom left-hand side of the screen, denoted by a simple line widget. This can be used to orient yourself while using the 3D camera/building levels.

Adding components to your Actor

You will notice that, if you try to scale or rotate the empty actor, nothing happens. That is because, at this point, the empty actor only contains a DefaultSceneRoot component. A component is an Object that is owned by other Unreal Engine 4 objects (usually Actors, Pawns, or Characters) that provide different functionalities/features to the object. In this case our actor owns a DefaultSceneRoot component allowing us to translate, rotate, and scale the object.

Why then does scaling and rotating do nothing? Well, right now we have no 'visual' components included in our actor and by that I mean any components that contain geometry that will visually represent the object in the game world. Without a visual reference, the orientation or size of the empty actor has no context, only the location of the object in 3D space could be of any use, thus we have the ability to translate.

This brings me to the second visual element; on the right-hand side of the window is the Details panel. This panel is used to show all information about any selected object within our world. From the Details panel we can manipulate exposed member data, add and remove components, and edit component properties. There are a few other tricks the Details panel offers us but I will expand upon those later on in the book.

You can also change the name of objects in the details panel. Right now our object is called Actor, we should change this to a more specific name, let's use Hello Sphere. Now we need to add a visual reference to our Hello Sphere. Under the Details panel you can see a green Add Component button; clicking this button will bring up a list of pre-built components we can add to our actor. We would like to add a Sphere to our actor, it can be found under the Basic Shapes section of the dropdown. You can either use the search bar provided to find specific components or scroll down the list until you find what you require.

The component hierarchy

Once you have added the sphere mesh to our Hello Sphere actor you will see a new element in the Details Panel, component hierarchy. We still have our DefaultSceneRoot component but now, directly under it, we have our sphere mesh. This brings up a very important point: Component parenting.

Within the Details panel you will notice that the sphere mesh component is indented slightly and directly beneath our DefaultSceneRoot component.

This is called parenting; our sphere mesh is now a child component of our DefaultSceneRoot component. This means that any scaling, rotation, or translation we apply to our DefaultSceneRoot will be applied to our sphere as well. However, any transformations we enact on our sphere mesh will not be applied to our DefaultSceneRoot. You can change the hierarchy of an object's components by clicking and dragging them up and down the list. The top-most component will be the Root Component and will dictate the transform of all subsequent components.

Ignoring this can lead to disjointing of child components and can be fairly troublesome. I encourage you to now translate the Hello Sphere with the Sphere component selected in the details panel, then again with the DefaultSceneRoot component selected instead. You will notice that, upon the second translation, the Sphere Mesh maintains its relative distance from the location of the DefaultSceneRoot component. It is because of this that I would strongly advise to only apply transformations to child objects when you wish those transformations to remain constant, relative to the parent.

Tip

If you wish to move everything within an object instance you may select the ObjectName (Instance) element within the hierarchy.

Modifying components

Now translate the Hello Sphere to the same location that the table and chairs originally occupied. We are going to add some Flash to our Hello Sphere. We are going to add two more components to the actor; a Text Render component and a Particle System component. We will then use the Details panel to modify the properties of these components to achieve our desired visual result.

First, let's modify the text. After adding a Text Render component, select it in the component hierarchy. You will see that the bottom section of the Details panel will change. This section is where you can modify the component's properties. You will notice that you can also get access to the component's transform properties here, this is so you can perform exact transformation changes to an object without having to use the transform widget.

Underneath the Transform and Materials sections we will see a section titled Text. It is here that the main properties for our Text Render component exist. The first thing we need to do is change the text so it says something meaningful. Let's change the Text field to Hello World then change the Horizontal Alignment field to Center.

Your Text section of the details panel should look something like this:

3D transformation and axis

Unfortunately the 3D text is partially penetrating the sphere mesh. To fix this we will be applying a translation to the Text Render component. We wish to apply this translation to the Text Render child component as we want this translation to remain the same regardless of the position of our actor. Instead of using the widget we can use the Transform section of the Details panel. You will notice a 3x3 field matrix under the Transform section. The top row represents the location of the component in 3D space, the second row the rotation, and the bottom row the scale. We want to move our 3D text vertically by a small amount and reduce the scale of our sphere so that our text sits above our sphere mesh.

3D game engines will use an arbitrary 3D co-ordinate system to accurately gauge the transformation of objects in 3D space. These co-ordinate systems are made up of three axis—X, Y, and Z. We gauge the direction of the co-ordinate axis by the direction in which the axis increases in a positive manner.

To better understand how axis work, we will take your position as a developer as a reference. If you were to see your own Unreal axis set, you would see a red axis (the X axis) extend outwards from your chest towards the screen. This is because the X axis in Unreal Engine increases in a positive manner forwards into the screen. In a similar fashion you would see a green axis extend out of your right-hand side (the Y axis), and finally you would have a blue axis extending upwards from your head (the Z axis). As an example, imagine the chair in the following screenshot is the chair you are sitting in:

We need to translate the text component 30cm positively along the Z axis. To do this, ensure that you have the Text Render component selected in the component hierarchy and simply change the third field in the top row of the Transform section of the Details panel to 30.0. However, our text render component is still intersecting with the sphere, we now need to scale down or shrink our sphere mesh component.

To scale down the sphere, make sure the Sphere Mesh component is selected in the component hierarchy, then press R to bring up the Scale Transform widget. You'll notice, as you hover your mouse over the different sections of the widget, that they will change to a yellow color. This means that if you were to press and hold the left mouse button, any movement of the mouse will result in a scale change on that axis. To scale the sphere along all axis uniformly, there is a small white box in the widget where all the axis meet. If your mouse is situated over this box, all of the axis will change to a yellow color. With this white box selected, click and drag the mouse to scale the sphere to half the size it was before. Or, alternatively, change all of the values in the bottom row of the transform matrix to 0.5.

This will move our text render component up and out of our smaller sphere mesh, resulting in something that looks like this:

Adding the Unreal factor

Our little sphere has come a long way, however we need to add something to our actor to make it stand out. This brings our other new component into focus, the Particle system. Particle systems are components that allow us to attach previously created particle effects to our actors. The creation of these particle effects and a more in-depth description will be detailed in the Boss Mode Activated chapter.

For now, we can use the new component's Details panel to modify which particle effect we would like to use and how it is transformed. With the Particle System component selected in the hierarchy, select the Template dropdown field in the Particles section and select P_Fire. This will use the P_Fire particle system template for the particle component. You may notice that the particle system is quite large initially; I scaled the system to about 1/3 of the original size. You can do this by using the scale widget or the transform field in the Details panel with the particle system component selected.

We are not done yet, Unreal Engine boasts a very flexible and feature-rich renderer. One of the most commonly used features is theMaterial system. Materials are pre-built visual effects we would like to apply to our surfaces. Materials encompass all surface details such as textures, color, and physical properties such as roughness and luminescence. The creation of Materials along with an in-depth description is covered in the Boss Mode Activated chapter. For now we can use a pre-made material for our Sphere Mesh. With the Sphere mesh component selected, click the dropdown field under the Materials section of the Details panel. Search in the list for M_Metal_Burnished_Steel. You'll notice that when the material is selected, the appearance of the sphere will change. You now see something similar to this:

And that is it! We are done setting up our game world for the Hello World project. Now you can click the large play button in the Toolbar at the top of the Editor window and fly around your new game world! You will notice at the top of the screen there are a few options, these in-editor play options will be explained in the next chapter Blueprints and Barrels. Congratulations on making your first Unreal Engine project Hello Unreal! All of the concepts presented in this project will be expanded on in much more detail in the following chapters. What you have learned here is only the beginning; there are many more interesting features and techniques yet to come.

Pre-Built projects as a learning resource

Now that you are comfortable creating and modifying your own projects, it is important to learn how to interact with the Unreal Learning tools to download pre-built projects so you may learn from other people's work.

Epic releases example projects that you can navigate and explore to learn about the different faces of the engine. If you open the Epic Games Launcher application and return to the Unreal Engine tab, you will notice in the list on the left-hand side of the screen a Learn element. Selecting this element will open up the Learn page of the Epic Game Launcher. From this page you can get access the engine documentation, video tutorials, community wiki and, most importantly, the example projects. If you scroll down, you will see a section titled Engine Feature Samples. This section holds all of the example projects that you can download to see how Epic Games implements the different feature sets of the Unreal Engine. The one in particular I would like to draw your attention to is the Content Examples project.

The Content Examples project features a set of levels that demonstrate the use of many of the Engine's features. If at any point the uses of the Engine's components seem unclear, you may be able to find an example of that component's implementation in this project. Once the project has been downloaded it will appear in the Library section of the Unreal Engine tab.

Summary

Well done on taking your first steps towards becoming an Unreal Engine developer! I hope you look forward to learning from this book and continuing your game development adventures with Unreal Engine 4. In this chapter you have learned how to install the engine, navigate its unique interface, and you have made your first Unreal Actor! The next chapter Barrels and Blueprints will expand on the skills you just have learned to create your first UE4 game project! You will be recreating a version of the classic arcade game Donkey Kong©. The chapter will have you learn more about interfacing with the engine editor, how to create a workflow with Unreal Engine, and how to work with the Blueprint visual scripting system.

Chapter 2. Blueprints and Barrels – Your First Game

Welcome to Blueprints andBarrels! During this chapter, you will be introduced to the visual scripting system called Blueprint. This system will be your first entry point toward creating customized functionality and content, using UE4. This chapter will show you the basics of how to create and work with Blueprints to achieve the same level of freedom that any other text based scripting language can provide. You will also expand on the engine navigational skills you learned in the previous chapter as we delve into the more complicated facets of the Editor panel and how you can communicate between the different components of the engine. You will learn all this by creating your very first UE game project, Barrel Hopper.

This chapter will cover the following points:

Creating BlueprintsNavigating the Blueprint GUIHow to find Blueprint functionsBasic coding functionality with Blueprint (logical nodes, objects, and events)Game mode BlueprintsUsing UE4's world outlinerBasic level creation and blockingBlueprint collisionAdding physics dynamics to objects in a worldCreating a Blueprint characterControlling a character through BlueprintDebugging Blueprints

Creating your first Blueprint

Now, it is time to create your first Blueprint. Instead of jumping straight into a new project, I can't think of a better place to create your first Blueprint than our Hello World project. It is time to give our Hello Sphere an upgrade! The first thing we need to do is create a Blueprint from our actor. To do this, we need to select the HelloSphere actor by clicking on the Actor in the viewport or selecting the HelloSphere name in the World Outlier. This will populate our Details Panel with the appropriate options. Just next to the Add Component button, there is a Blueprint/Add Script button, click on this now:

You will be prompted to save the Blueprint we are about to create in some folder within our Content Browser. For now, save the blueprint in the Content folder directly. Name this Bluerpint HelloUnrealBP and press the green Create Blueprint button.

The Blueprint window

You will have been presented with an entirely new window, the Blueprint window. This will be your work area whenever you are editing or creating Blueprints. The Blueprint window boasts a new layout of panels and visual sections:

Components: Located in the top left-hand side of the window, this panel functions in exactly the same way as the top of the Details panel in the editor window. You can use this panel to add and remove components.My Blueprint: Located directly under the Components panel, this panel is responsible for all of the different technical members of the Blueprint. This is where you can find your Event Graphs, Events, Functions, Macros, Variables, and Event Dispatchers. Each of these elements will be described in detail throughout the chapter.Details: This panel functions exactly the same way as is it did in the editor window. This panel exposes all of the publicly exposed properties of your currently selected component within the Blueprint.Toolbar: The toolbar is located in center of the screen at the top and features a set of large clickable buttons. These buttons will be explained in the next paragraph.Viewport: This viewport section is responsible for showing the current physical arrangement of the blueprint in 3D space. This section will also be used to navigate the graphs or functions that are created with the Blueprint system. These other panels can be seen as tabs along the top of the viewport window. By default, Viewport, Construction Script, and Event Graph are shown.

Working with Blueprints

When creating Blueprints, you are frequently going to want to test your recent changes and additional functions as intended. You will also want to make sure that you have minimal errors, warnings, or bugs. The way you will do this is by interfacing with the previously mentioned Toolbar. The buttons featured on the Toolbar allow you to perform varying actions that assist with having your Blueprint execute in a test environment. Each button performs the follows:

Compile: This compiles the current Blueprint and will output any errors or warnings. You can specify various parameters for Blueprint compilation that will adjust if the file is saved and how Blueprint compile errors are handled. These parameters can be found by navigating to Editor Preferences | Content Editors | Blueprint.Save: This saves the Blueprint.Find in CB: This opens the content browser and navigate to a selected asset. This lets you locate any assets included in your Blueprint within your content browser. This can be useful if you wish to edit these assets midway through working with a Blueprint.Class Settings: This opens a Details panel that is responsible for all of the Blueprint Properties such as the Blueprints Parent class, thumbnail appearance, and any interfaces the Blueprint is concerned with. These options will be covered when we look at advanced blueprint functionality.Class Defaults: This opens a Details panel that is responsible for the default values of all of the publically exposed variables that can be found in the Blueprint and its components. This lets you specify what state you would like these variable to be in when an instance of this Blueprint is created in a game.Simulation: This runs the Blueprint as a simulation. The simulation takes place within the Blueprint viewport. This lets you witness how the Blueprint will function within the game without having to create an instance in the level and running the game.Play: This runs the current project, and functions in the same way as the play button within the editor window. The main difference is the drop-down window located next to the Play button. This lets you select the in-Editor Blueprint instance you wish to scrutinize for debugging. Note that this kind of playing in the editor is known as a PIE (Play In Editor) session

All of these options provide you the ability to debug and run your Blueprints while working on them in your project.

Tip

Once you are familiar with the engine and you no longer need the tabs describing the title of each panel. You can right-click on the tab and select the Hide Tab option, so you can maximize available screen space.

Blueprint elements

Each Blueprint will include and be composed of certain elements, these elements can be found under the My Blueprint panel. Each of these elements will be used by you to create the custom functionality that you require from your Blueprint.

Graphs

Blueprint Graphs are the canvas with which you work to create blueprint functionality. It is within these graphs that you will place and connect your Blueprint nodes. Event Graphs house the Events that will be fired during a Blueprint's application lifetime. These events can be things like the Tick event that will be called every frame or the ActorBeginOverlap event that will be called when the Blueprint object is overlapping another. Blueprint functions and Macros will also be constructed using the graph system; however, these graphs will be independent.

Functions

Blueprint functions are a means of wrapping frequently used functionality or functionality that you wish to expose to other objects These functions act in a very similar way to standard C++ functions. You may also specify an encapsulation level when working with Blueprint functions (public, protected, and private). Blueprint functions allow you to specify both input and return parameters.

Macros

Similar to functions but are only internally facing, meaning that they can only be called from within the Blueprint itself. Macros are predominantly used for grouping sets of simple instructions that will be called very frequently. The major difference between Blueprint functions and Blueprint macros is that macros are inlined when the Blueprint is compiled. As UE4 is a C++ based engine, all blueprints are eventually compiled down into generated C++ that can be then again compiled into executable binary. When I state that the Macros are inlined, I am speaking of traditional C++ inlining to the macro function itself it its generated C++ form.

Variables

Blueprint variables allow you to create data types that can store information. These variables are very similar to Class Member Variables in C++. You can specify an encapsulation level and default values for Blueprint variables. It is also important to note that, for every component included in a blueprint, there will be a corresponding variable that will act as a reference to the component. This allows you to access components form within your blueprint graphs.

Event dispatchers

Event dispatchers allow you to bind events to one another. For example, if you wanted some functionality to