Book Image

Unreal Engine 5 Game Development with C++ Scripting

By : ZHENYU GEORGE LI
Book Image

Unreal Engine 5 Game Development with C++ Scripting

By: ZHENYU GEORGE LI

Overview of this book

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.
Table of Contents (18 chapters)
1
Part 1 – Getting Started with Unreal C++ Scripting
6
Part 2 – C++ Scripting for Unreal Engine
12
Part 3: Making a Complete Multiplayer Game

Refactoring code

You probably felt a little uncomfortable with the redundant code blocks we wrote in the previous chapters; for example, the PlayerAvatar and Enemy classes have some identical attribute variables and functions. Can we instead combine them and maintain only one copy of code for those replicated variables and functions? Yes, and this will require us to refactor the code.

Code refactoring helps improve the internal structure of code so that it becomes more readable, maintainable, and efficient. The process includes algorithm optimization, duplicate removal, and code simplification.

For the Pangaea project, we identified two refactoring tasks:

  • Combining the two animation instance classes
  • Adding a parent class for the PlayerAvatar and Enemy classes

Let’s start with the first task.

Combining the PlayerAvatarAnimInstance and EnemyAnimInstance classes

Open and compare the PlayerAvatarAnimInstance.h, PlayerAvatarAnimInstance.cpp, EnemyAnimInstance...