Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unreal Engine 5 Game Development with C++ Scripting

You're reading from  Unreal Engine 5 Game Development with C++ Scripting

Product type Book
Published in Aug 2023
Publisher Packt
ISBN-13 9781804613931
Pages 384 pages
Edition 1st Edition
Languages
Author (1):
ZHENYU GEORGE LI ZHENYU GEORGE LI
Profile icon ZHENYU GEORGE LI

Table of Contents (18) Chapters

Preface 1. Part 1 – Getting Started with Unreal C++ Scripting
2. Chapter 1: Creating Your First Unreal C++ Game 3. Chapter 2: Editing C++ Code in Visual Studio 4. Chapter 3: Learning C++ and Object-Oriented Programming 5. Chapter 4: Investigating the Shooter Game’s Generated Project and C++ Code 6. Part 2 – C++ Scripting for Unreal Engine
7. Chapter 5: Learning How to Use UE Gameplay Framework Base Classes 8. Chapter 6: Creating Game Actors 9. Chapter 7: Controlling Characters 10. Chapter 8: Handling Collisions 11. Chapter 9: Improving C++ Code Quality 12. Part 3: Making a Complete Multiplayer Game
13. Chapter 10: Making Pangaea a Network Multiplayer Game 14. Chapter 11: Controlling the Game Flow 15. Chapter 12: Polishing and Packaging the Game 16. Index 17. Other Books You May Enjoy

Editing C++ Code in Visual Studio

Are you new to coding in general? Then you need to use an editing tool!

C++ source code is just regular text files named with some special extension names, such as .cpp, .h, and so on. You can basically use Windows Notepad to open and edit C++ source code files. However, since Notepad is a basic editing tool that lacks functionalities, we recommend using Visual Studio (VS) as the code editor.

Why use VS? VS is a feature-rich integrated development environment (IDE) that supports many aspects of software development. It empowers you to complete the entire development cycle in one place. You can use VS to create, edit, debug, test, and build your code. VS also has the most popular programming language compilers integrated with the installation package so that C++ source code can be directly compiled to be executable machinery code. Moreover, VS especially supports Unreal Engine and works well with the engine’s development environment.

...

Technical requirements

To explore the creation of C++ projects and editing C++ code, it is necessary to have VS installed on your system.

VS has both Windows and macOS versions. It also has Community, Professional, and Enterprise editions. The examples of this book are based on the VS 2022 Windows Community edition.

Since VS is an IDE that you will use for C++ scripting, being familiar with the development environment and the scripting skills is a prerequisite.

The code for this chapter can be found at https://github.com/PacktPublishing/Unreal-Engine-5-Game-Development-with-C-Scripting/tree/main/Chapter02/MyCPP_01.

Launching VS

In Chapter 1, we went through the installation of VS, so you should already have installed VS on your system. Since VS is an independent application, you can launch it either from the operating system (OS) or in Unreal Engine.

In Windows, simply search for virtual studio and pick the version of the IDE that you wish to launch:

Figure 2.1 – Starting VS in Windows

Figure 2.1 – Starting VS in Windows

Now, let’s practice launching VS in Unreal Engine. Say we want to open the MyShooterCharacter.cpp file—you first need to find MyShooter/All/C++ Classes/MyShooter on the Content Drawer, and then you can double-click on the MyShooterCharacter C++ Class item:

Figure 2.2 – Starting VS in Unreal Engine

Figure 2.2 – Starting VS in Unreal Engine

This operation will launch VS if it hasn’t been launched yet and open the MyShooterCharacter.cpp file in the editor:

Figure 2.3 – VS opened MyShooterCharacter.cpp

Figure 2.3 – VS opened MyShooterCharacter.cpp

Now, you should have...

Walking through the VS IDE’s UI

VS is a powerful and complex tool set. This book only covers features and functionalities that you will need for learning C++ scripting. You can visit Microsoft’s official websites to learn more about VS in the future. Here are the links:

Once you have opened VS, you will see the IDE editor:

Figure 2.4 – VS IDE editor

Figure 2.4 – VS IDE editor

Using Figure 2.4, let’s take a look at all the important elements present in the editor.

Code editor

The code editor on the left side is the place where you write your C++ code. You can open multiple source code files in the code editor. The opened filename tabs are displayed at the top of the editor. Figure 2.5 shows four source code files opened in the editor: MyShooterGameMode.cpp, MyShooterGameMode...

Editing code in VS

The VS IDE has ample powerful editing features and tools that can help developers effectively create and edit their code. Almost all the tools can be found on the main menu system. Here, we'll only introduce the commonly used editing tools and the shortcut keys that can help you to get started. It is recommended to utilize and practice the following shortcuts and keys in your later exercises.

Controlling the caret (input cursor)

The caret is often represented as a blinking vertical line when editing in VS. It indicates the current input point and determines where new text will be entered.

Knowing how to use the keys for caret navigation is an essential editing skill, so let’s find out a bit more about this:

  • Up, Down, Left, Right arrow keys: Move the caret up, down, left, or right, respectively
  • Home, End: Move the caret to the beginning or the end of a code line, respectively
  • Ctrl + Home, Ctrl + End: Move the caret to the beginning...

Practicing C++ coding

Now, it’s time to practice writing C++ code in VS. To simplify the learning process and avoid noise from the Unreal Engine code, we will use a pure C++ solution as the learning example.

Here are some recommendations to consider while editing the code:

  • You don’t need to fully comprehend the source code at this stage; simply copy the provided C++ code in this section and concentrate on the editor features, as the C++ programming syntax will be introduced in the next chapter.
  • Try using the introduced VS editing keys as much as possible.
  • Type the code manually instead of relying on copy and paste, as this will assist you in quickly mastering editing skills and becoming familiar with the editing environment.

So, let’s get started.

Creating a new C++ solution in VS

Begin by starting VS from Windows and selecting Create a new project:

 Figure 2.9 – VS: Creating a new project

Figure 2.9 – VS: Creating a new project

Then...

Summary

By walking through the content in this chapter, you should have mastered basic code editing skills in VS. Being familiar with the IDE and the editing tools is fundamental for learning C++ scripting in the next chapters, and will also help in your future Unreal Engine game development practices.

The shortcut keys and the functions introduced in this chapter are particularly useful tools that you will want to remember and use when you edit your code—they will benefit you in terms of both your coding performance and code quality.

We also practiced creating and editing C++ source code in a C++ solution. Based on this, we will continue learning more C++ programming syntax, structural programming, and object-oriented programing (OOP) in the next chapter.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Unreal Engine 5 Game Development with C++ Scripting
Published in: Aug 2023 Publisher: Packt ISBN-13: 9781804613931
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime}