Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unreal Engine 5 Game Development with C++ Scripting

You're reading from   Unreal Engine 5 Game Development with C++ Scripting Become a professional game developer and create fully functional, high-quality games

Arrow left icon
Product type Paperback
Published in Aug 2023
Publisher Packt
ISBN-13 9781804613931
Length 384 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
ZHENYU GEORGE LI ZHENYU GEORGE LI
Author Profile Icon ZHENYU GEORGE LI
ZHENYU GEORGE LI
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Part 1 – Getting Started with Unreal C++ Scripting
2. Chapter 1: Creating Your First Unreal C++ Game FREE CHAPTER 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

Creating your C++ Shooter project from a template

Now, it’s the time to get your hands dirty working on a UE5 C++ project yourself. We will go through the steps to create a new C++ project from scratch based on the First Person template.

The First Person template is one of the default game templates that come with UE. When you want to create a new project, you can pick this template from the Unreal Project Browser window. Our new MyShooter game will derive all the features from the template game, and we don’t have to do any additional work.

To get started with C++ scripting, we first need to install an IDE. In this book, we will use MS Visual Studio 2022 as an example.

Installing Visual Studio 2022

Visual Studio (VS) is an Integrated Development Environment (IDE) from Microsoft. It is a tool used to create, edit, debug, and compile code. In order to do C++ scripting, you need to go to the official website at https://visualstudio.microsoft.com/vs/ and download the Community 2022 version installation package (see Figure 1.1).

Figure 1.1 – Downloading VS 2022

Figure 1.1 – Downloading VS 2022

Note

To install VS, a Microsoft account is typically required. If you don’t have a Microsoft account, you can register using the following page: https://account.microsoft.com/account/.

Next, launch VisualStudioSetup.exe inside the folder where you downloaded the VS installer (the \Downloads folder, for example).

Enable the two Game development with C++ and Desktop development with C++ checkboxes – these two options tell the installer to install the C++ compiler and the professional game development support for UE (see Figure 1.2).

Figure 1.2 – Picking workloads for the VS installation

Figure 1.2 – Picking workloads for the VS installation

Also, keep an eye on the following options on the Installation details panel that belongs to the Desktop development with C++ group, and make sure the following are checked:

  • C++ profiling tools
  • C++ AddressSanitizer
  • Windows 10 SDK
  • IntelliCode
  • IDE support for Unreal Engine

Then, click the Install button to install the workloads and reboot the system, and then you will see a prompt from the dialog popup (see Figure 1.3):

Figure 1.3 – The VS Done installing dialog box

Figure 1.3 – The VS Done installing dialog box

The next thing we need to do is to confirm that we have installed the engine source code together with the UE5 editor. The reason why we need this is that when we generate a new project, the engine source code can be integrated into the new project; under certain circumstances, we may need to modify or customize the engine for the game’s specific needs.

Ensuring your UE has the source code installed

Before launching the UE5 editor, we first need to check whether Engine Source is installed for the editor. By doing this check, we make sure that the UE5 source code is integrated with the C++ projects we are going to create.

The three steps to check or install the engine source code are as follows:

  1. Click the downward arrow button and choose Options from the drop-down menu.
  2. Make sure that the Engine Source option is checked.
  3. Press the Apply button:
Figure 1.4 – The UE5 Options menu

Figure 1.4 – The UE5 Options menu

UE is an ongoing development product, with bugs and defects that may need to be fixed by its users. Also, professional developers sometimes modify the engine source code to adapt to their specific needs. An example of this is when we face an issue with geometry instancing (or instanced rendering) working only in the game’s development build but not in the release build, which is subsequently resolved by our engineer modifying the engine’s source code.

Note

Geometry instancing is a rendering technique that renders multiple instances of a visual object in a single draw call and provides each instance with some unique attributes: https://en.wikipedia.org/wiki/Geometry_instancing.

We are now ready to start the UE editor through the Epic Games Launcher.

Launching the UE5 editor through the Epic Games Launcher

Launching the UE5 editor is pretty straightforward. You simply click the Launch button on the 5.03 engine card to start the editor (see Figure 1.5).

Figure 1.5 – Launching the UE5 editor from the Epic Games Launcher

Figure 1.5 – Launching the UE5 editor from the Epic Games Launcher

The next thing we want to do is to create a new game project. Let’s name the new project MyShooter.

Creating the MyShooter C++ project

To create the project, follow these steps (and see Figure 1.6 for reference):

  1. In the Unreal Project Browser window, choose the GAMES tab on the left side.
  2. Select the First Person template.
  3. Select the C++ button.
  4. Choose the project location (for example, C:\UEProjects) and type MyShooter in the Project Name field.
  5. Click the Create button.
Figure 1.6 – Creating the MyShooter project

Figure 1.6 – Creating the MyShooter project

The created game project also includes the starter content, which is packaged with assets and resources that can be used to prototype the game.

The engine will do some initialization work and then open the editor when things are ready. If you look at the project tree panel’s MyShooter tab in the bottom-left corner of the editor window, you should see the C++ Classes node on the same layer as the Content node (see Figure 1.7).

Figure 1.7 – The MyShooter C++ project opened in the UE5 editor

Figure 1.7 – The MyShooter C++ project opened in the UE5 editor

Associating VS with UE5 as the default source code editor

Since we created the C++, project, all the C++ source code for the game was already generated. To open the source files directly in the UE5 editor, we want to associate VS as the engine editor’s default IDE.

On the UE5 Editor’s main menu, select Edit | Editor Preferences to open the preference window, then find the General | Source Code item on the left panel, and finally, pick Visual Studio 2022 from the Source Code Editor dropdown (see Figure 1.8).

Figure 1.8 – Making VS the default source code editor

Figure 1.8 – Making VS the default source code editor

You can now use VS to open the source code files.

Opening the C++ source code in VS (optional)

If you want to open and view the C++ source code in VS, you can find the source code file (for example, C++/MyShooter/MyShooterCharacter.cpp) in the project and simply double-click on it (see Figure 1.9).

Figure 1.9 – Opening MyShooterCharacter.cpp source code in VS

Figure 1.9 – Opening MyShooterCharacter.cpp source code in VS

The system will automatically launch VS, and the VS editor will open the MyShooterCharacter.cpp file (see Figure 1.10).

Figure 1.10 – Viewing the MyShooterCharacter.cpp source code in VS

Figure 1.10 – Viewing the MyShooterCharacter.cpp source code in VS

Back in the Unreal editor, click the Play (A picture containing text, electronics, clock radio

Description automatically generated) button to start the game. While playing the game on the battlefield, you can control your character, move them around, and pick up the gun in front of them (see Figure 1.11).

Figure 1.11 – Playing the MyShooter game

Figure 1.11 – Playing the MyShooter game

We have learned how to create a UE C++ project from scratch. However, what if we already have a Blueprint project and want to convert it to a C++ project? UE allows developers to do it by adding a new C++ class to the project. Let’s practice converting a MyBPShooter Blueprint project.

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 €18.99/month. Cancel anytime