Unreal Engine 5 Game Development with C++ Scripting

Book description

Expand your UE5 game development skills by leveraging C++ scripting and improve your game development abilities by building a game from scratch Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • Learn C++ programming as well as C++ scripting for Unreal Engine 5
  • Practice the UE5 scripting APIs through a game project to improve your knowledge and skills
  • Explore essential techniques and development cycles including design, implementation, optimization, and publishing

Book Description

Unreal Engine is one of the most popular and accessible game engines in the industry, creating multiple job opportunities. Owing to C++ scripting's high performance, advanced algorithms, and engineering maintenance, it has become the industry standard for developing commercial games. However, C++ scripting can be overwhelming for anyone without a programming background. Unreal Engine 5 Game Development with C++ Scripting will help you master C++ and get a head start on your game development journey.

You’ll start by creating an Unreal Engine C++ project from the shooter template and then move on to building the C++ project and the C++ code inside the Visual Studio editor. You’ll be introduced to the fundamental C++ syntax and essential object-oriented programming concepts. For a holistic understanding of game development, you’ll also uncover various aspects of the game, including character creation, player input and character control, gameplay, collision detection, UI, networking, and packaging a completed multiplayer game.

By the end of this book, you’ll be well-equipped to create professional, high-quality games using Unreal Engine 5 with C++, and will have built a solid foundation for more advanced C++ programming and game development technologies.

What you will learn

  • Develop coding skills in Microsoft Visual Studio and the Unreal Engine editor
  • Discover C++ programming for Unreal Engine C++ scripting
  • Understand object-oriented programming concepts and C++-specific syntax
  • Explore NPC controls, collisions, interactions, navigation, UI, and the multiplayer mechanism
  • Use the predefined Unreal Engine classes and the programming mechanism
  • Write code to solve practical problems and accomplish tasks
  • Implement solutions and methods used in game development

Who this book is for

This book is for game designers, artists, software engineers, and students with some experience in using Unreal Engine and looking to explore the enigmatic C++ scripting. Basic experience with the UE editor is expected and blueprint scripting is a must. Familiarity with game concepts such as game level, lights, camera, actor/pawn/character, transformation, animation, and player control will be beneficial.

Table of contents

  1. Unreal Engine 5 Game Development with C++ Scripting
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Share Your Thoughts
    8. Download a free PDF copy of this book
  7. Part 1 – Getting Started with Unreal C++ Scripting
  8. Chapter 1: Creating Your First Unreal C++ Game
    1. Technical requirements
    2. Understanding C++ scripting in Unreal
      1. What is the difference between C++ and Blueprint?
      2. When do you use C++?
      3. What is the difference between C++ programming and C++ scripting?
    3. Creating your C++ Shooter project from a template
      1. Installing Visual Studio 2022
      2. Ensuring your UE has the source code installed
      3. Launching the UE5 editor through the Epic Games Launcher
      4. Creating the MyShooter C++ project
      5. Associating VS with UE5 as the default source code editor
      6. Opening the C++ source code in VS (optional)
    4. Converting an existing Blueprint project to a C++ project
    5. Summary
  9. Chapter 2: Editing C++ Code in Visual Studio
    1. Technical requirements
    2. Launching VS
    3. Walking through the VS IDE’s UI
      1. Code editor
      2. Menus
      3. Search box
      4. Toolbar
      5. Solution Explorer
      6. Output window
      7. Error List window
    4. Editing code in VS
      1. Controlling the caret (input cursor)
      2. The text editing keys
      3. Code selection
      4. IntelliSense
      5. Useful editing hotkeys
    5. Practicing C++ coding
      1. Creating a new C++ solution in VS
      2. Creating the main.cpp file
      3. Changing the editor theme
      4. Writing the initial code for main.cpp
      5. Adding the Calculator class
    6. Summary
  10. Chapter 3: Learning C++ and Object-Oriented Programming
    1. Technical requirements
    2. What is C++?
    3. Exploring the C++ program structure
    4. Defining C++ functions
      1. Defining functions with or without parameters
      2. Calling functions
      3. Writing the main() function
    5. Working with a basic calculator program
    6. Learning the C++ syntax
      1. Using the C++ data types
      2. Defining variables
      3. Using C++ arrays
      4. Using C++ operators
      5. Accepting user input
      6. Adding C++ comments
      7. Controlling the C++ flow
    7. Working on the improved calculator program
    8. Creating references and pointers
      1. References
      2. Pointers
    9. Understanding OOP
      1. What is OOP?
      2. What are classes and objects?
      3. Creating classes in C++
      4. Creating objects in C++
    10. Working on an OOP calculator program
      1. Adding constructor and getter functions for the calculator class
      2. Creating the CalculatorEx class, which inherits from the Calculator class
    11. Summary
  11. Chapter 4: Investigating the Shooter Game’s Generated Project and C++ Code
    1. Technical requirements
    2. Understanding the MyShooter C++ project structure
    3. Understanding the game program structure
    4. Getting familiar with the source code
      1. MyShooterCharacter.h
      2. MyShooterCharacter.cpp
      3. MyShooterProjectile.h and MyShooterProjectile.cpp
      4. TP_PickUpComponent.h and TP_PickUpComponent.cpp
      5. TP_WeaponComponent.h and TP_WeaponComponent.cpp
      6. MyShooter.h and MyShooter.cpp
      7. MyShooterGameMode.h and MyShooterGameMode.cpp
      8. MyShooter.Build.cs, MyShooter.Target.cs, and MyShooterEditor.target.cs
    5. Launching Unreal Editor and opening the game project in Visual Studio
    6. Summary
  12. Part 2 – C++ Scripting for Unreal Engine
  13. Chapter 5: Learning How to Use UE Gameplay Framework Base Classes
    1. Technical requirements
    2. Creating a Pangaea top-down game project
    3. Understanding the gameplay framework base classes
    4. Creating game actor classes
      1. Creating the ADefenseTower class
      2. Creating the AProjectile class
      3. Creating the APlayerAvatar class
    5. Recompiling C++ projects
    6. Using the UPROPERTY macro
      1. The UPROPERTY syntax
      2. The UPROPERTY specifiers and metadata keys
      3. Marking the ADefenseTower, AProjectile, and APlayerAvatar attributes as UE properties
    7. Using the UFUNCTION macro
      1. The UFUNCTION syntax
      2. UFUNCTION specifiers and metadata keys
      3. Tagging ADefenseTower and APlayerAvatar member functions as UFUNCTION macros
    8. Adding components to the new actors
      1. Including component header files
      2. Defining private properties for these two components
      3. Adding public getter functions to the components
      4. Creating components in the class constructor
    9. Creating blueprints from the new actor classes
    10. Learning about the Unreal gameplay framework classes
      1. Locating and creating gameplay framework classes in Pangaea
      2. Learning about the PlayerController class
      3. Learning about the GameModeBase class
      4. GameState
      5. GameInstance
      6. Retrieving class instances from your code
    11. Using the Cast template function
    12. Summary
  14. Chapter 6: Creating Game Actors
    1. Technical requirements
    2. Setting up the player avatar
      1. Adding SpringArmComponent and CameraComponent to PlayerAvatar
      2. Initializing the player avatar
    3. Setting up the character’s SkeletalMeshComponent
      1. Importing the character model
      2. Using the Hero skeletal mesh in BP_PlayerAvatar
      3. Replacing the game’s player pawn
    4. Creating the player avatar’s animation blueprint
      1. Creating the PlayerAvatarAnimInstance class
      2. Creating the ABP_PlayerAvatar blueprint
      3. Creating the State Machine on ABP_PlayerAvatar
      4. Syncing the movement speed with the animation instance
    5. Summary
  15. Chapter 7: Controlling Characters
    1. Technical requirements
    2. Controlling the player character to attack
      1. Adding the Attack action to the action map
      2. Binding the handler function to the Attack action
      3. Implementing the OnAttackPressed() action handler function
      4. Implementing the CanAttack() and Attack() functions
      5. Processing non-loop animations
      6. Implementing the OnStateAnimationEnds function
    3. Destroying actors
    4. Creating the enemy character
      1. Creating the Enemy class
      2. Creating the EnemyController class
      3. Creating the ABP_Enemy animation blueprint
      4. Creating the BP_Enemy blueprint
    5. Testing the game
    6. Summary
  16. Chapter 8: Handling Collisions
    1. Technical requirements
    2. Understanding collision detection
    3. Setting the collision presets
    4. Using collisions for game interactions
      1. Downloading and creating the weapon, defense tower, and fireball actors
      2. Picking up weapons
      3. Spawning a weapon for the enemy
      4. Defense tower firing fireballs
      5. Moving the fireball and checking whether the target is hit
      6. Processing a defense tower hit
    5. Summary
  17. Chapter 9: Improving C++ Code Quality
    1. Technical requirements
    2. Refactoring code
      1. Combining the PlayerAvatarAnimInstance and EnemyAnimInstance classes
      2. Making PangaeaCharacter the parent class of APlayerAvatar and AEnemy
    3. Refining code
      1. Using caching variables
      2. Creating a fireball pool
    4. Outputting debug messages
      1. Using the UE_LOG macro
      2. Printing debug messages to the screen
    5. Checking an Actor instance’s actual class type
    6. Summary
  18. Part 3: Making a Complete Multiplayer Game
  19. Chapter 10: Making Pangaea a Network Multiplayer Game
    1. Technical requirements
    2. Comparing single-player and multiplayer games
    3. Launching the multiplayer Pangaea game in the editor
    4. Understanding multiplayer game network modes
    5. Handling network synchronizations
      1. Notifying player attacks with RPCs
      2. Syncing actor variables to clients with replications
      3. Updating the character health bar with RepNotify
      4. Processing hits on the server
      5. Spawning fireballs on the server side
    6. Summary
  20. Chapter 11: Controlling the Game Flow
    1. Technical requirements
    2. Designing the Pangaea game’s flow
    3. Creating the UI widgets
      1. Creating BP_LobbyWidget
      2. Creating BP_HUDWidget
      3. Creating BP_GameOverWidget
    4. Adding networking functions to PangaeaGameInstance
    5. Adding UI widgets to game levels
    6. Adding the game timer
      1. Adding the Timer variable to the APangaeaGameState class
      2. Making the Timer variable replicable
      3. Defining OnTimeChangedDelegate
      4. Creating and binding the custom event to OnTimeChangedDelegate
      5. Counting down the timer
      6. Designating APangaeaGameState as the project’s game state class
    7. Destroying a base defense tower to win the game
    8. Summary
  21. Chapter 12: Polishing and Packaging the Game
    1. Technical requirements
    2. Polishing the game
      1. Importing and using high-quality game assets
      2. Fixing bugs
      3. Profiling and optimization
    3. Using Unreal Engine console commands
      1. Exploring modes and console commands
      2. Executing console commands in C++
    4. Packaging the game
      1. Configuring the project settings for packaging
      2. Making the build a windowed game
      3. Avoiding the hardcoded path for finding content
      4. Packaging the project
    5. What to do next
    6. Summary
  22. Index
    1. Why subscribe?
  23. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Unreal Engine 5 Game Development with C++ Scripting
  • Author(s): ZHENYU GEORGE LI
  • Release date: August 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781804613931