Cover....1
Title Page....2
Copyright and Credits....3
Foreword....4
Contributors....5
Table of Contents....8
Preface....14
Part 1 – Getting Started with Unreal C++ Scripting....22
Chapter 1: Creating Your First Unreal C++ Game....24
Technical requirements....24
Understanding C++ scripting in Unreal....25
What is the difference between C++ and Blueprint?....25
When do you use C++?....26
What is the difference between C++ programming and C++ scripting?....26
Creating your C++ Shooter project from a template....27
Installing Visual Studio 2022....27
Ensuring your UE has the source code installed....30
Launching the UE5 editor through the Epic Games Launcher....31
Creating the MyShooter C++ project....31
Associating VS with UE5 as the default source code editor....33
Opening the C++ source code in VS (optional)....34
Converting an existing Blueprint project to a C++ project....36
Summary....41
Chapter 2: Editing C++ Code in Visual Studio....42
Technical requirements....42
Launching VS....43
Walking through the VS IDE’s UI....45
Code editor....46
Menus....47
Search box....47
Toolbar....47
Solution Explorer....47
Output window....48
Error List window....49
Editing code in VS....50
Controlling the caret (input cursor)....51
The text editing keys....51
Code selection....51
IntelliSense....52
Useful editing hotkeys....52
Practicing C++ coding....53
Creating a new C++ solution in VS....54
Creating the main.cpp file....56
Changing the editor theme....58
Writing the initial code for main.cpp....59
Adding the Calculator class....61
Summary....63
Chapter 3: Learning C++ and Object-Oriented Programming....64
Technical requirements....65
What is C++?....65
Exploring the C++ program structure....66
Defining C++ functions....67
Defining functions with or without parameters....68
Calling functions....68
Writing the main() function....68
Working with a basic calculator program....69
Learning the C++ syntax....70
Using the C++ data types....71
Defining variables....72
Using C++ arrays....73
Using C++ operators....74
Accepting user input....78
Adding C++ comments....78
Controlling the C++ flow....79
Working on the improved calculator program....87
Creating references and pointers....93
References....94
Pointers....95
Understanding OOP....95
What is OOP?....96
What are classes and objects?....96
Creating classes in C++....97
Creating objects in C++....98
Working on an OOP calculator program....99
Adding constructor and getter functions for the calculator class....104
Creating the CalculatorEx class, which inherits from the Calculator class....105
Summary....109
Chapter 4: Investigating the Shooter Game’s Generated Project and C++ Code....110
Technical requirements....110
Understanding the MyShooter C++ project structure....111
Understanding the game program structure....113
Getting familiar with the source code....116
MyShooterCharacter.h....116
MyShooterCharacter.cpp....121
MyShooterProjectile.h and MyShooterProjectile.cpp....124
TP_PickUpComponent.h and TP_PickUpComponent.cpp....127
TP_WeaponComponent.h and TP_WeaponComponent.cpp....129
MyShooter.h and MyShooter.cpp....131
MyShooterGameMode.h and MyShooterGameMode.cpp....131
MyShooter.Build.cs, MyShooter.Target.cs, and MyShooterEditor.target.cs....132
Launching Unreal Editor and opening the game project in Visual Studio....133
Summary....135
Part 2 – C++ Scripting for Unreal Engine....136
Chapter 5: Learning How to Use UE Gameplay Framework Base Classes....138
Technical requirements....139
Creating a Pangaea top-down game project....139
Understanding the gameplay framework base classes....140
Creating game actor classes....141
Creating the ADefenseTower class....141
Creating the AProjectile class....146
Creating the APlayerAvatar class....146
Recompiling C++ projects....148
Using the UPROPERTY macro....149
The UPROPERTY syntax....150
The UPROPERTY specifiers and metadata keys....151
Marking the ADefenseTower, AProjectile, and APlayerAvatar attributes as UE properties....151
Using the UFUNCTION macro....153
The UFUNCTION syntax....153
UFUNCTION specifiers and metadata keys....153
Tagging ADefenseTower and APlayerAvatar member functions as UFUNCTION macros....154
Adding components to the new actors....157
Including component header files....157
Defining private properties for these two components....157
Adding public getter functions to the components....158
Creating components in the class constructor....159
Creating blueprints from the new actor classes....159
Learning about the Unreal gameplay framework classes....163
Locating and creating gameplay framework classes in Pangaea....163
Learning about the PlayerController class....164
Learning about the GameModeBase class....165
GameState....165
GameInstance....165
Retrieving class instances from your code....166
Using the Cast template function....166
Summary....168
Chapter 6: Creating Game Actors....170
Technical requirements....170
Setting up the player avatar....171
Adding SpringArmComponent and CameraComponent to PlayerAvatar....171
Initializing the player avatar....175
Setting up the character’s SkeletalMeshComponent....176
Importing the character model....176
Using the Hero skeletal mesh in BP_PlayerAvatar....181
Replacing the game’s player pawn....181
Creating the player avatar’s animation blueprint....183
Creating the PlayerAvatarAnimInstance class....184
Creating the ABP_PlayerAvatar blueprint....190
Creating the State Machine on ABP_PlayerAvatar....192
Syncing the movement speed with the animation instance....195
Summary....197
Chapter 7: Controlling Characters....200
Technical requirements....201
Controlling the player character to attack....201
Adding the Attack action to the action map....201
Binding the handler function to the Attack action....202
Implementing the OnAttackPressed() action handler function....203
Implementing the CanAttack() and Attack() functions....203
Processing non-loop animations....205
Implementing the OnStateAnimationEnds function....207
Destroying actors....208
Creating the enemy character....210
Creating the Enemy class....211
Creating the EnemyController class....216
Creating the ABP_Enemy animation blueprint....221
Creating the BP_Enemy blueprint....222
Testing the game....224
Summary....225
Chapter 8: Handling Collisions....226
Technical requirements....226
Understanding collision detection....227
Setting the collision presets....231
Using collisions for game interactions....234
Downloading and creating the weapon, defense tower, and fireball actors....235
Picking up weapons....239
Spawning a weapon for the enemy....245
Defense tower firing fireballs....246
Moving the fireball and checking whether the target is hit....251
Processing a defense tower hit....255
Summary....257
Chapter 9: Improving C++ Code Quality....260
Technical requirements....260
Refactoring code....261
Combining the PlayerAvatarAnimInstance and EnemyAnimInstance classes....261
Making PangaeaCharacter the parent class of APlayerAvatar and AEnemy....264
Refining code....276
Using caching variables....276
Creating a fireball pool....277
Outputting debug messages....284
Using the UE_LOG macro....285
Printing debug messages to the screen....286
Checking an Actor instance’s actual class type....287
Summary....290
Part 3 – Making a Complete Multiplayer Game....292
Chapter 10: Making Pangaea a Network Multiplayer Game....294
Technical requirements....294
Comparing single-player and multiplayer games....295
Launching the multiplayer Pangaea game in the editor....296
Understanding multiplayer game network modes....298
Handling network synchronizations....299
Notifying player attacks with RPCs....299
Syncing actor variables to clients with replications....303
Updating the character health bar with RepNotify....305
Processing hits on the server....311
Spawning fireballs on the server side....312
Summary....314
Chapter 11: Controlling the Game Flow....316
Technical requirements....316
Designing the Pangaea game’s flow....317
Creating the UI widgets....318
Creating BP_LobbyWidget....319
Creating BP_HUDWidget....322
Creating BP_GameOverWidget....324
Adding networking functions to PangaeaGameInstance....327
Adding UI widgets to game levels....331
Adding the game timer....333
Adding the Timer variable to the APangaeaGameState class....334
Making the Timer variable replicable....335
Defining OnTimeChangedDelegate....335
Creating and binding the custom event to OnTimeChangedDelegate....336
Counting down the timer....338
Designating APangaeaGameState as the project’s game state class....340
Destroying a base defense tower to win the game....341
Summary....347
Chapter 12: Polishing and Packaging the Game....348
Technical requirements....348
Polishing the game....349
Importing and using high-quality game assets....349
Fixing bugs....352
Profiling and optimization....352
Using Unreal Engine console commands....353
Exploring modes and console commands....353
Executing console commands in C++....357
Packaging the game....359
Configuring the project settings for packaging....359
Making the build a windowed game....361
Avoiding the hardcoded path for finding content....362
Packaging the project....365
What to do next....368
Summary....369
Index....370
Other Books You May Enjoy....381
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.