Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition

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.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Unreal Engine 4.x Scripting with C++ Cookbook Second Edition
  3. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  4. www.PacktPub.com
    1. Why subscribe?
    2. Packt.com
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  6. UE4 Development Tools
    1. Introduction
    2. Technical requirements
    3. Installing Visual Studio
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating and building your first C++ project in Visual Studio
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Changing the code font and color in Visual Studio
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Extension – changing the color theme in Visual Studio
      1. How to do it...
      2. How it works...
    7. Formatting your code (Autocomplete settings) in Visual Studio
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Shortcut keys in Visual Studio
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Extended mouse usage in Visual Studio
      1. How to do it...
      2. How it works...
    10. Installing Unreal Engine 4 (UE4)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Creating your first project in UE4
      1. How to do it...
    12. Creating your first level in UE4
      1. Getting ready
      2. How to do it...
    13. UE4 – hot reloading
      1. Getting ready
      2. How to do it...
    14. UE4 – logging with UE_LOG
      1. Getting ready
      2. How to do it...
      3. How it works...
    15. UE4 – making an FString from FStrings and other variables
      1. Getting ready
      2. How to do it...
  7. Creating Classes
    1. Introduction
    2. Technical requirements
    3. Making a UCLASS – deriving from UObject
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Creating a blueprint from your custom UCLASS
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a user-editable UPROPERTY
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Accessing a UPROPERTY from blueprints
      1. How to do it...
      2. How it works...
    7. Specifying a UCLASS as the type of a UPROPERTY
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. TSubclassOf
        2. FStringClassReference
    8. Instantiating UObject-derived classes (ConstructObject< > and NewObject< >)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Destroying UObject-derived classes
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating a USTRUCT
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Creating a UENUM( )
      1. How to do it...
      2. How it works...
  8. Memory Management, Smart Pointers, and Debugging
    1. Introduction
    2. Technical requirements
    3. Unmanaged memory – using malloc( ) / free( )
      1. How to do it...
      2. How it works...
    4. Unmanaged memory – using new/delete
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Managed memory – using NewObject< > and ConstructObject< >
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Managed memory – de-allocating memory
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Managed memory – smart pointers (TSharedPtr, TWeakPtr, TAutoPtr) to track an object
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Using TScopedPointer to track an object
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Unreal's garbage collection system and UPROPERTY( )
      1. How to do it...
      2. How it works...
    10. Forcing garbage collection
      1. Getting ready
      2. How to do it...
    11. Breakpoints and stepping through code
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Finding bugs and using call stacks
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Using the profiler to identify hot spots
      1. How to do it...
      2. How it works...
  9. Actors and Components
    1. Introduction
    2. Technical requirements
    3. Creating a custom Actor in C++
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Instantiating an Actor using SpawnActor
      1. How to do it...
      2. How it works...
    5. Creating a UFUNCTION
      1. How to do it...
      2. How it works...
    6. Destroying an Actor using Destroy and a Timer
      1. How to do it...
      2. How it works...
    7. Destroying an Actor after a delay using SetLifeSpan
      1. How to do it...
      2. How it works...
    8. Implementing the Actor functionality by composition
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Loading assets into components using FObjectFinder
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Implementing the Actor functionality by inheritance
      1. How to do it...
      2. How it works...
      3. See also
    11. Attaching components to create a hierarchy
      1. How to do it...
      2. How it works...
    12. Creating a custom Actor Component
      1. How to do it...
      2. How it works...
    13. Creating a custom Scene Component
      1. How to do it...
      2. How it works...
      3. See also
    14. Creating an InventoryComponent for an RPG
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    15. Creating an OrbitingMovement Component
      1. How to do it...
      2. How it works...
    16. Creating a building that spawns units
      1. How to do it...
      2. How it works...
  10. Handling Events and Delegates
    1. Introduction
    2. Technical requirements
    3. Handling events that have been implemented via virtual functions
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Creating a delegate that is bound to a UFUNCTION
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Unregistering a delegate
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating a delegate that takes input parameters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Passing payload data with a delegate binding
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Creating a multicast delegate
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating a custom Event
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Creating a Time of Day handler
      1. How to do it...
      2. How it works...
    11. Creating a respawning pickup for a First Person Shooter
      1. How to do it...
      2. How it works...
  11. Input and Collision
    1. Introduction
    2. Technical requirements
    3. Axis Mappings – keyboard, mouse, and gamepad directional input for an FPS character
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Axis Mappings – normalized input
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Action Mappings – one-button responses for an FPS character
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Adding Axis and Action Mappings from C++
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Mouse UI input handling
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. UMG keyboard UI shortcut keys
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Collision – letting objects pass through one another using Ignore
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Collision – picking up objects using Overlap
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Collision – preventing interpenetration using Block
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  12. Communication Between Classes and Interfaces: Part I
    1. Introduction
    2. Technical requirements
    3. Creating a UInterface
      1. How to do it...
      2. How it works...
      3. See also
    4. Implementing a UInterface on an object
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Checking if a class implements a UInterface
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Casting to a UInterface implemented in native code
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Calling native UInterface functions from C++
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Inheriting UInterfaces from one another
      1. How to do it...
      2. How it works...
    9. Overriding UInterface functions in C++
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Implementing a simple interaction system with UInterfaces
      1. Getting ready...
      2. How to do it...
      3. How it works...
  13. Communication Between Classes and Interfaces: Part II
    1. Introduction
    2. Technical requirements
    3. Exposing UInterface methods to Blueprint from a native base class
      1. How to do it...
      2. How it works...
      3. See also
    4. Implementing UInterface functions in Blueprint
      1. How to do it...
      2. How it works...
      3. See also
    5. Overriding C++ UInterface functions through Blueprints 
      1. How to do it...
      2. How it works...
    6. Calling Blueprint-defined interface functions from C++
      1. How to do it...
      2. How it works...
  14. Integrating C++ and the Unreal Editor: Part I
    1. Introduction
    2. Technical requirements
    3. Using a class or struct as a blueprint variable
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Creating classes or structs that can be subclassed in Blueprint
      1. How to do it...
      2. How it works...
    5. Creating functions that can be called in Blueprint
      1. How to do it...
      2. How it works...
      3. See also
    6. Creating events that can be implemented in Blueprints
      1. How to do it...
      2. How it works...
    7. Exposing multi-cast delegates to Blueprint
      1. How to do it...
      2. How it works...
      3. See also
    8. Creating C++ enums that can be used in Blueprint
      1. How to do it...
      2. How it works...
    9. Editing class properties in different places in the editor
      1. How to do it...
      2. How it works...
      3. See also
    10. Making properties accessible in the Blueprint editor graph
      1. How to do it...
      2. How it works...
    11. Responding to property changed events from the editor
      1. How to do it...
      2. How it works...
    12. Implementing a native code Construction Script
      1. How to do it...
      2. How it works...
  15. Integrating C++ and the Unreal Editor: Part II
    1. Introduction
    2. Creating a new editor module
      1. How to do it...
      2. How it works...
    3. Creating new toolbar buttons
      1. How to do it...
      2. How it works...
    4. Creating new menu entries
      1. How to do it...
      2. How it works...
    5. Creating a new editor window
      1. How to do it...
      2. How it works...
      3. See also
    6. Creating a new Asset type
      1. How to do it...
      2. How it works...
      3. See also
    7. Creating custom context menu entries for Assets
      1. How to do it...
      2. How it works...
    8. Creating new console commands
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Creating a new graph pin visualizer for Blueprint
      1. How to do it...
      2. How it works...
    10. Inspecting types with custom Details panels
      1. How to do it...
      2. How it works...
  16. Working with UE4 APIs
    1. Introduction
    2. Technical requirements
    3. Core/Logging API – defining a custom log category
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Core/Logging API – FMessageLog to write messages to the Message Log
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Core/Math API – rotation using FRotator
      1. Getting ready
      2. How to do it...
    6. Core/Math API – rotation using FQuat
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. API – rotation using FRotationMatrix to have one object face another
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. GameplayAbilities API – triggering an actor's gameplay abilities with game controls
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. GameplayAbilities API - Implementing stats with UAttributeSet
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. GameplayAbilities API – implementing buffs with GameplayEffect
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. GameplayTasks API – making things happen with GameplayTasks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    12. HTTP API – downloading webpages using web requests
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    13. HTTP API – displaying downloaded progress 
      1. Getting ready
      2. How to do it...
      3. How it works...
  17. Multiplayer Networking in UE4
    1. Introduction
    2. Technical requirements
    3. Testing your game as a client and a server simultaneously
      1. How to do it...
      2. How it works...
    4. Replicating properties over the network
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Replicating functions over the network
      1. How to do it...
      2. How it works...
      3. See also...
    6. Handling UI network events
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. See also...
  18. AI for Controlling NPCs
    1. Introduction
    2. Technical requirements
    3. Implementing a simple following behavior
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Laying down a Navigation Mesh
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a Blackboard
      1. How to do it...
      2. How it works...
    6. Creating a Behavior Tree
      1. How to do it...
      2. How it works...
    7. Connecting a Behavior Tree to a Character
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a BTService
      1. Getting ready...
      2. How to do it...
      3. How it works...
    9. Creating a BTTask
      1. Getting ready...
      2. How to do it...
      3. How it works...
  19. User Interfaces - UI and UMG
    1. Introduction
    2. Technical requirements
    3. Drawing using Canvas
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. See also...
    4. Adding Slate Widgets to the screen
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating screen size-aware scaling for the UI
      1. Getting ready
      2. How to do it...
        1. Using the In-Editor method
        2. Using the Config file method
      3. How it works...
      4. See also
    6. Displaying and hiding a sheet of UMG elements in-game
      1. How to do it...
      2. How it works...
    7. Attaching function calls to Slate events
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using Data Binding with Unreal Motion Graphics
      1. How to do it...
      2. How it works...
    9. Controlling widget appearance with Styles
      1. How to do it...
      2. How it works...
    10. Creating a custom SWidget/UWidget
      1. Getting ready
      2. How to do it...
      3. How it works...
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition
  • Author(s): John P. Doran, William Sherif, Stephen Whittle
  • Release date: March 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789809503