Reader small image

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

Product typeBook
Published inAug 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804613931
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
ZHENYU GEORGE LI
ZHENYU GEORGE LI
author image
ZHENYU GEORGE LI

Zhenyu George Li is a passionate video game developer with 20+ years of experience. He has contributed significantly to many games and serves as a senior development consultant at Unity. His early immersion in technologies like C/C++, DirectX, OpenGL, and Windows GUI laid the foundation for his success. Notable titles in his portfolio include Magic Arena, Halo Infinity, Stela, Dead Rising 2, and The Bigs 2. He has gained extensive knowledge in programming, graphics, animation, gameplay, AI, multiplayer, and UI using Unreal and Unity engines. Additionally, he has taught UE at Vancouver Film School and has college teaching experience at College of Interactive Arts and Hefei Union University.
Read more about ZHENYU GEORGE LI

Right arrow

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.

Previous PageNext Page
You have been reading a chapter from
Unreal Engine 5 Game Development with C++ Scripting
Published in: Aug 2023Publisher: PacktISBN-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.
undefined
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

Author (1)

author image
ZHENYU GEORGE LI

Zhenyu George Li is a passionate video game developer with 20+ years of experience. He has contributed significantly to many games and serves as a senior development consultant at Unity. His early immersion in technologies like C/C++, DirectX, OpenGL, and Windows GUI laid the foundation for his success. Notable titles in his portfolio include Magic Arena, Halo Infinity, Stela, Dead Rising 2, and The Bigs 2. He has gained extensive knowledge in programming, graphics, animation, gameplay, AI, multiplayer, and UI using Unreal and Unity engines. Additionally, he has taught UE at Vancouver Film School and has college teaching experience at College of Interactive Arts and Hefei Union University.
Read more about ZHENYU GEORGE LI