Unreal Engine 4 Scripting with C++ Cookbook

Get the best out of your games by scripting them using UE4

Unreal Engine 4 Scripting with C++ Cookbook

This ebook is included in a Mapt subscription
William Sherif, Stephen Whittle

2 customer reviews
Get the best out of your games by scripting them using UE4
$10.00
$49.99
RRP $39.99
RRP $49.99
eBook
Print + eBook
Preview in Mapt

Book Details

ISBN 139781785885549
Paperback452 pages

Book Description

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

Chapter 1: UE4 Development Tools
Introduction
Installing Visual Studio
Creating and building your first C++ project in Visual Studio
Changing the code font and color in Visual Studio
Extension – changing the color theme in Visual Studio
Formatting your code (Autocomplete settings) in Visual Studio
Shortcut keys in Visual Studio
Extended mouse usage in Visual Studio
UE4 – installation
UE4 – first project
UE4 – creating your first level
UE4 – logging with UE_LOG
UE4 – making an FString from FStrings and other variables
Project management on GitHub – getting your Source Control
Project management on GitHub – using the Issue Tracker
Project management on VisualStudio.com – managing the tasks in your project
Project management on VisualStudio.com – constructing user stories and tasks
Chapter 2: Creating Classes
Introduction
Making a UCLASS – deriving from UObject
Creating a user-editable UPROPERTY
Accessing a UPROPERTY from Blueprints
Specifying a UCLASS as the type of a UPROPERTY
Creating a Blueprint from your custom UCLASS
Instantiating UObject-derived classes (ConstructObject < > and NewObject < >)
Destroying UObject-derived classes
Creating a USTRUCT
Creating a UENUM( )
Creating a UFUNCTION
Chapter 3: Memory Management and Smart Pointers
Introduction
Unmanaged memory – using malloc( )/free( )
Unmanaged memory – using new/delete
Managed memory – using NewObject< > and ConstructObject< >
Managed memory – deallocating memory
Managed memory – smart pointers (TSharedPtr, TWeakPtr, TAutoPtr) to track an object
Using TScopedPointer to track an object
Unreal's garbage collection system and UPROPERTY( )
Forcing garbage collection
Breakpoints and stepping through code
Finding bugs and using call stacks
Using the Profiler to identify hot spots
Chapter 4: Actors and Components
Introduction
Creating a custom Actor in C++
Instantiating an Actor using SpawnActor
Destroying an Actor using Destroy and a Timer
Destroying an Actor after a delay using SetLifeSpan
Implementing the Actor functionality by composition
Loading assets into components using FObjectFinder
Implementing the Actor functionality by inheritance
Attaching components to create a hierarchy
Creating a custom Actor Component
Creating a custom Scene Component
Creating a custom Primitive Component
Creating an InventoryComponent for an RPG
Creating an OrbitingMovement Component
Creating a building that spawns units
Chapter 5: Handling Events and Delegates
Handling events implemented via virtual functions
Creating a delegate that is bound to a UFUNCTION
Unregistering a delegate
Creating a delegate that takes input parameters
Passing payload data with a delegate binding
Creating a multicast delegate
Creating a custom Event
Creating a Time of Day handler
Creating a respawning pickup for an First Person Shooter
Chapter 6: Input and Collision
Introduction
Axis Mappings – keyboard, mouse and gamepad directional input for an FPS character
Axis Mappings – normalized input
Action Mappings – one button responses for an FPS character
Adding Axis and Action Mappings from C++
Mouse UI input handling
UMG keyboard UI shortcut keys
Collision – letting objects pass through one another using Ignore
Collision – picking up objects using Overlap
Collision – preventing interpenetration using Block
Chapter 7: Communication between Classes and Interfaces
Introduction
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 UInterface from one another
Overriding UInterface functions in C++
Exposing UInterface methods to Blueprint from a native base class
Implementing UInterface functions in Blueprint
Creating C++ UInterface function implementations that can be overridden in Blueprint
Calling Blueprint-defined interface functions from C++
Implementing a simple interaction system with UInterfaces
Chapter 8: Integrating C++ and the Unreal Editor
Introduction
Using a class or struct as a blueprint variable
Creating classes or structs that can be subclassed in Blueprint
Creating functions that can be called in Blueprint
Creating events that can be implemented in Blueprint
Exposing multi-cast delegates to Blueprint
Creating C++ enums that can be used in Blueprint
Editing class properties in different places in the editor
Making properties accessible in the Blueprint editor graph
Responding to property – changed events from the editor
Implementing a native code Construction Script
Creating a new editor module
Creating new toolbar buttons
Creating new menu entries
Creating a new editor window
Creating a new Asset type
Creating custom context menu entries for Assets
Creating new console commands
Creating a new graph pin visualizer for Blueprint
Inspecting types with custom Details panels
Chapter 9: User Interfaces – UI and UMG
Introduction
Drawing using Canvas
Adding Slate Widgets to the screen
Creating screen size-aware scaling for the UI
Displaying and hiding a sheet of UMG elements in-game
Attaching function calls to Slate events
Use Data Binding with Unreal Motion Graphics
Controlling widget appearance with Styles
Create a custom SWidget/UWidget
Chapter 10: AI for Controlling NPCs
Introduction
Laying down a Navigation Mesh
Following behavior
Connecting a Behavior Tree to a Character
Constructing Task nodes
Using Decorators for conditions
Using periodic services
Using Composite nodes – Selectors, Sequences, and Simple Parallel
AI for a Melee Attacker
Chapter 11: Custom Materials and Shaders
Introduction
Modifying color using a basic Material
Modifying position using a Material
Shader code via Custom node
The Material function
Shader parameters and Material instances
Glimmer
Leaves and Wind
Reflectance dependent on the viewing angle
Randomness – Perlin noise
Shading a Landscape
Chapter 12: Working with UE4 APIs
Introduction
Core/Logging API – Defining a custom log category
Core/Logging API – FMessageLog to write messages to the Message Log
Core/Math API – Rotation using FRotator
Core/Math API – Rotation using FQuat
Core/Math API – Rotation using FRotationMatrix to have one object face another
Landscape API – Landscape generation with Perlin noise
Foliage API – Adding trees procedurally to your level
Landscape and Foliage API – Map generation using Landscape and Foliage APIs
GameplayAbilities API – Triggering an actor's gameplay abilities with game controls
GameplayAbilities API – Implementing stats with UAttributeSet
GameplayAbilities API – Implementing buffs with GameplayEffect
GameplayTags API – Attaching GameplayTags to an Actor
GameplayTasks API – Making things happen with GameplayTasks
HTTP API – Web request
HTTP API – Progress bars

What You Will Learn

  • Build function libraries (Blueprints) containing reusable code to reduce upkeep
  • Move low-level functions from Blueprint into C++ to improve performance
  • Abstract away complex implementation details to simplify designer workflows
  • Incorporate existing libraries into your game to add extra functionality such as hardware integration
  • Implement AI tasks and behaviors in Blueprints and C++
  • Generate data to control the appearance and content of UI elements

Authors

Table of Contents

Chapter 1: UE4 Development Tools
Introduction
Installing Visual Studio
Creating and building your first C++ project in Visual Studio
Changing the code font and color in Visual Studio
Extension – changing the color theme in Visual Studio
Formatting your code (Autocomplete settings) in Visual Studio
Shortcut keys in Visual Studio
Extended mouse usage in Visual Studio
UE4 – installation
UE4 – first project
UE4 – creating your first level
UE4 – logging with UE_LOG
UE4 – making an FString from FStrings and other variables
Project management on GitHub – getting your Source Control
Project management on GitHub – using the Issue Tracker
Project management on VisualStudio.com – managing the tasks in your project
Project management on VisualStudio.com – constructing user stories and tasks
Chapter 2: Creating Classes
Introduction
Making a UCLASS – deriving from UObject
Creating a user-editable UPROPERTY
Accessing a UPROPERTY from Blueprints
Specifying a UCLASS as the type of a UPROPERTY
Creating a Blueprint from your custom UCLASS
Instantiating UObject-derived classes (ConstructObject < > and NewObject < >)
Destroying UObject-derived classes
Creating a USTRUCT
Creating a UENUM( )
Creating a UFUNCTION
Chapter 3: Memory Management and Smart Pointers
Introduction
Unmanaged memory – using malloc( )/free( )
Unmanaged memory – using new/delete
Managed memory – using NewObject< > and ConstructObject< >
Managed memory – deallocating memory
Managed memory – smart pointers (TSharedPtr, TWeakPtr, TAutoPtr) to track an object
Using TScopedPointer to track an object
Unreal's garbage collection system and UPROPERTY( )
Forcing garbage collection
Breakpoints and stepping through code
Finding bugs and using call stacks
Using the Profiler to identify hot spots
Chapter 4: Actors and Components
Introduction
Creating a custom Actor in C++
Instantiating an Actor using SpawnActor
Destroying an Actor using Destroy and a Timer
Destroying an Actor after a delay using SetLifeSpan
Implementing the Actor functionality by composition
Loading assets into components using FObjectFinder
Implementing the Actor functionality by inheritance
Attaching components to create a hierarchy
Creating a custom Actor Component
Creating a custom Scene Component
Creating a custom Primitive Component
Creating an InventoryComponent for an RPG
Creating an OrbitingMovement Component
Creating a building that spawns units
Chapter 5: Handling Events and Delegates
Handling events implemented via virtual functions
Creating a delegate that is bound to a UFUNCTION
Unregistering a delegate
Creating a delegate that takes input parameters
Passing payload data with a delegate binding
Creating a multicast delegate
Creating a custom Event
Creating a Time of Day handler
Creating a respawning pickup for an First Person Shooter
Chapter 6: Input and Collision
Introduction
Axis Mappings – keyboard, mouse and gamepad directional input for an FPS character
Axis Mappings – normalized input
Action Mappings – one button responses for an FPS character
Adding Axis and Action Mappings from C++
Mouse UI input handling
UMG keyboard UI shortcut keys
Collision – letting objects pass through one another using Ignore
Collision – picking up objects using Overlap
Collision – preventing interpenetration using Block
Chapter 7: Communication between Classes and Interfaces
Introduction
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 UInterface from one another
Overriding UInterface functions in C++
Exposing UInterface methods to Blueprint from a native base class
Implementing UInterface functions in Blueprint
Creating C++ UInterface function implementations that can be overridden in Blueprint
Calling Blueprint-defined interface functions from C++
Implementing a simple interaction system with UInterfaces
Chapter 8: Integrating C++ and the Unreal Editor
Introduction
Using a class or struct as a blueprint variable
Creating classes or structs that can be subclassed in Blueprint
Creating functions that can be called in Blueprint
Creating events that can be implemented in Blueprint
Exposing multi-cast delegates to Blueprint
Creating C++ enums that can be used in Blueprint
Editing class properties in different places in the editor
Making properties accessible in the Blueprint editor graph
Responding to property – changed events from the editor
Implementing a native code Construction Script
Creating a new editor module
Creating new toolbar buttons
Creating new menu entries
Creating a new editor window
Creating a new Asset type
Creating custom context menu entries for Assets
Creating new console commands
Creating a new graph pin visualizer for Blueprint
Inspecting types with custom Details panels
Chapter 9: User Interfaces – UI and UMG
Introduction
Drawing using Canvas
Adding Slate Widgets to the screen
Creating screen size-aware scaling for the UI
Displaying and hiding a sheet of UMG elements in-game
Attaching function calls to Slate events
Use Data Binding with Unreal Motion Graphics
Controlling widget appearance with Styles
Create a custom SWidget/UWidget
Chapter 10: AI for Controlling NPCs
Introduction
Laying down a Navigation Mesh
Following behavior
Connecting a Behavior Tree to a Character
Constructing Task nodes
Using Decorators for conditions
Using periodic services
Using Composite nodes – Selectors, Sequences, and Simple Parallel
AI for a Melee Attacker
Chapter 11: Custom Materials and Shaders
Introduction
Modifying color using a basic Material
Modifying position using a Material
Shader code via Custom node
The Material function
Shader parameters and Material instances
Glimmer
Leaves and Wind
Reflectance dependent on the viewing angle
Randomness – Perlin noise
Shading a Landscape
Chapter 12: Working with UE4 APIs
Introduction
Core/Logging API – Defining a custom log category
Core/Logging API – FMessageLog to write messages to the Message Log
Core/Math API – Rotation using FRotator
Core/Math API – Rotation using FQuat
Core/Math API – Rotation using FRotationMatrix to have one object face another
Landscape API – Landscape generation with Perlin noise
Foliage API – Adding trees procedurally to your level
Landscape and Foliage API – Map generation using Landscape and Foliage APIs
GameplayAbilities API – Triggering an actor's gameplay abilities with game controls
GameplayAbilities API – Implementing stats with UAttributeSet
GameplayAbilities API – Implementing buffs with GameplayEffect
GameplayTags API – Attaching GameplayTags to an Actor
GameplayTasks API – Making things happen with GameplayTasks
HTTP API – Web request
HTTP API – Progress bars

Book Details

ISBN 139781785885549
Paperback452 pages
Read More
From 2 reviews

Read More Reviews