Book description
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.
Table of contents
- Title Page
- Copyright and Credits
- Contributors
- www.PacktPub.com
- Preface
-
UE4 Development Tools
- Introduction
- Technical requirements
- 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
- Installing Unreal Engine 4 (UE4)
- Creating your first project in UE4
- Creating your first level in UE4
- UE4 – hot reloading
- UE4 – logging with UE_LOG
- UE4 – making an FString from FStrings and other variables
-
Creating Classes
- Introduction
- Technical requirements
- Making a UCLASS – deriving from UObject
- Creating a blueprint from your custom UCLASS
- Creating a user-editable UPROPERTY
- Accessing a UPROPERTY from blueprints
- Specifying a UCLASS as the type of a UPROPERTY
- Instantiating UObject-derived classes (ConstructObject< > and NewObject< >)
- Destroying UObject-derived classes
- Creating a USTRUCT
- Creating a UENUM( )
-
Memory Management, Smart Pointers, and Debugging
- Introduction
- Technical requirements
- Unmanaged memory – using malloc( ) / free( )
- Unmanaged memory – using new/delete
- Managed memory – using NewObject< > and ConstructObject< >
- Managed memory – de-allocating 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
-
Actors and Components
- Introduction
- Technical requirements
- Creating a custom Actor in C++
- Instantiating an Actor using SpawnActor
- Creating a UFUNCTION
- 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 an InventoryComponent for an RPG
- Creating an OrbitingMovement Component
- Creating a building that spawns units
-
Handling Events and Delegates
- Introduction
- Technical requirements
- Handling events that have been 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 a First Person Shooter
-
Input and Collision
- Introduction
- Technical requirements
- 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
-
Communication Between Classes and Interfaces: Part I
- Introduction
- Technical requirements
- 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
- Communication Between Classes and Interfaces: Part II
-
Integrating C++ and the Unreal Editor: Part I
- Introduction
- Technical requirements
- 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 Blueprints
- 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
-
Integrating C++ and the Unreal Editor: Part II
- Introduction
- 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
-
Working with UE4 APIs
- Introduction
- Technical requirements
- 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
- API – rotation using FRotationMatrix to have one object face another
- GameplayAbilities API – triggering an actor's gameplay abilities with game controls
- GameplayAbilities API - Implementing stats with UAttributeSet
- GameplayAbilities API – implementing buffs with GameplayEffect
- GameplayTasks API – making things happen with GameplayTasks
- HTTP API – downloading webpages using web requests
- HTTP API – displaying downloaded progress
- Multiplayer Networking in UE4
- AI for Controlling NPCs
-
User Interfaces - UI and UMG
- Introduction
- Technical requirements
- 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
- Using Data Binding with Unreal Motion Graphics
- Controlling widget appearance with Styles
- Creating a custom SWidget/UWidget
- Other Books You May Enjoy
Product information
- Title: Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition
- Author(s):
- Release date: March 2019
- Publisher(s): Packt Publishing
- ISBN: 9781789809503
You might also like
book
Unreal Engine 4 Scripting with C++ Cookbook
Get the best out of your games by scripting them using UE4 About This Book A …
book
Unreal Engine 5 Game Development with C++ Scripting
Expand your UE5 game development skills by leveraging C++ scripting and improve your game development abilities …
book
Beginning C++ Game Programming - Second Edition
Get to grips with programming techniques and game development using C++ libraries and Visual Studio 2019 …
book
Beginning Unreal Engine 4 Blueprints Visual Scripting: Using C++: From Beginner to Pro
Discover how Unreal Engine 4 allows you to create exciting games using C++ and Blueprints. This …