Unreal Engine 4.x Scripting with C++ Cookbook
Develop quality game components and solve scripting problems with the power of C++ and UE4, 2nd Edition
John P. Doran, William Sherif, Stephen Whittle
- 708 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Unreal Engine 4.x Scripting with C++ Cookbook
Develop quality game components and solve scripting problems with the power of C++ and UE4, 2nd Edition
John P. Doran, William Sherif, Stephen Whittle
About This Book
Write efficient, reusable scripts to build custom characters, game environments, and control enemy AI
Key Features
- Build captivating multiplayer games using Unreal Engine and C++
- Incorporate existing C++ libraries into your game to add extra functionality such as hardware integration
- Practical solutions for memory management, error handling, inputs, and collision for your game codebase
Book Description
Unreal Engine 4 (UE4) is a popular and award-winning game engine that powers some of the most popular games. A truly powerful tool for game development, there has never been a better time to use it for both commercial and independent projects. With more than 100 recipes, this book shows how to unleash the power of C++ while developing games with Unreal Engine.
This book takes you on a journey to jumpstart your C++ and UE4 development skills. You will start off by setting up UE4 for C++ development and learn how to work with Visual Studio, a popular code editor. You will learn how to create C++ classes and structs the Unreal way. This will be followed by exploring memory management, smart pointers, and debugging your code. You will then learn how to make your own Actors and Components through code and how to handle input and collision events. You will also get exposure to many elements of game development including creating user interfaces, artificial intelligence, and writing code with networked play in mind. You will also learn how to add on to the Unreal Editor itself.
With a range of task-oriented recipes, this book provides actionable information about writing code for games with UE4 using C++. By the end of the book, you will be empowered to become a top-notch developer with UE4 using C++ as your scripting language!
What you will learn
- Create C++ classes and structs that integrate well with UE4 and the Blueprints editor
- Discover how to work with various APIs that Unreal Engine already contains
- Utilize advanced concepts such as events, delegates, and interfaces in your UE4 projects
- Build user interfaces using Canvas and UMG through C++
- Extend the Unreal Editor by creating custom windows and editors
- Implement AI tasks and services using C++, Blackboard, and Behavior Trees
- Write C++ code with networking in mind and replicate properties and functions
Who this book is for
If you are really passionate game developer looking for solutions to common scripting problems, then this is the book for you. Understanding of the fundamentals of game design and C++ is expected to get the most from this book.
Frequently asked questions
Information
Communication Between Classes and Interfaces: Part I
- Creating a UInterface
- Implementing a UInterface on an object
- Checking if a class implements a UInterface
- Casting to a UInterface implemented in native code
- Calling native UInterface functions from C++
- Inheriting UInterfaces from one another
- Overriding UInterface functions in C++
- Implementing a simple interaction system with UInterfaces
Introduction
Technical requirements
Creating a UInterface
How to do it...
- From the Content Browser, go to Add New | New C++ Class. From the menu that pops up, scroll down all the way until you see the Unreal Interface selection and select it. Afterward, click on the Next button:
- From there, verify that the Name of the class is MyInterface and then click on the Create Class button:
- Add the following code to the header file:
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MyInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UMyInterface : public UInterface
{
GENERATED_BODY()
};
class CHAPTER_07_API IMyInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that
//will be inherited to implement this interface.
public:
virtual FString GetTestName();
};
- Implement the class with this code in the .cpp file:
#include "MyInterface.h"
// Add default functionality here for any IMyInterface functions that are not pure virtual.
FString IMyInterface::GetTestName()
{
unimplemented();
return FString();
}
- Compile your project to verify that the code was written without errors.