Unreal Engine 4 Scripting with C++ Cookbook

Book description

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

About This Book

  • A straightforward and easy-to-follow format
  • A selection of the most important tasks and problems
  • Carefully organized instructions to solve problems efficiently
  • Clear explanations of what you did
  • Solutions that can be applied to solve real-world problems

Who This Book Is For

This book is intended for game developers who understand the fundamentals of game design and C++ and would like to incorporate native code into the games they make with Unreal. They will be programmers who want to extend the engine, or implement systems and Actors that allow designers control and flexibility when building levels.

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

In Detail

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.

Style and approach

A recipe based practical guide to show you how you can leverage C++ to manipulate and change your game behavior and game design using Unreal Engine 4.

Table of contents

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

Product information

  • Title: Unreal Engine 4 Scripting with C++ Cookbook
  • Author(s): William Sherif, Stephen Whittle
  • Release date: October 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781785885549