Reader small image

You're reading from  Game Development Projects with Unreal Engine

Product typeBook
Published inNov 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781800209220
Edition1st Edition
Languages
Tools
Right arrow
Authors (4):
Hammad Fozi
Hammad Fozi
author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

Gonçalo Marques
Gonçalo Marques
author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

David Pereira
David Pereira
author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

Devin Sherry
Devin Sherry
author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry

View More author details
Right arrow

Working with the Visual Studio Solution

Every C++ project in Unreal Engine has a Visual Studio solution. This, in turn, drives all the code and provides developers with the ability to set up execution logic and debug code in its running state.

Solution Analysis

The Visual Studio solution (.sln) file that's produced inside the project directory contains the entire project and any associated code that's been added to it.

Let's have a look at the files present in Visual Studio. Double-click the .sln file to open it within Visual Studio.

In Solution Explorer, you will see two projects called Engine and Games.

The Engine Project

At the base level, Unreal Engine itself is a Visual Studio project and has its own solution file. This contains all the code and third-party integrations that work together in Unreal Engine. All the code within this project is called the "source" code.

The Engine project consists of the external dependencies, configurations, plugins, shaders, and source code of Unreal Engine that are currently being used for this project. You can, at any time, browse the UE4 -> Source folder to view any of the engine code.

Note

As Unreal Engine is open source, Epic allows developers to both view and edit source code to suit their needs and requirements. However, you cannot edit the source code in the version of Unreal Engine that's installed via the Epic Games Launcher. To be able to make and build changes in source code, you need to download the source version of Unreal Engine, which can be found via GitHub. You can use the following guide to download the Source Version of the Unreal Engine: https://docs.unrealengine.com/en-US/GettingStarted/DownloadingUnrealEngine/index.html

After downloading, you can also refer to the following guide for compiling/building the newly downloaded engine: https://docs.unrealengine.com/en-US/Programming/Development/BuildingUnrealEngine/index.html

Game Project

Under the Games directory is the solution folder with the name of your project. Upon expansion, you'll find a set of folders. You will be concerned with the following:

  • Config Folder: Carries all the configurations that have been set up for the project and the build (these can optionally have platform-specific (such as Windows, Android, iOS, Xbox, or PS) settings as well).
  • Plugins Folder: This is an optional folder that's created when you add any third-party plugin (downloaded from the Epic Marketplace or obtained through the internet). This folder will contain all of the source code of the plugins associated with this project.
  • Source Folder: This is the primary folder we're going to be working with. It will contain the Build Target files, as well as all the source code for the project. The following is a description of the default files in the source folder:
  • Target and Build Files: These (as shown in the following screenshot) contain code that specifies the Unreal Build Tool (the program that builds your game) that you will use to build your game. It contains any extra modules that need to be added to the game, as well as other build-related settings. By default, there are two target files (one for Unreal Editor and another for the build as depicted by their names), which end with the .Target.cs extension, and one build file that ends with Build.cs.
  • ProjectName code files (.cpp & .h): By default, these files are created for each project and contain the code that's used to run the default game module code.
  • ProjectNameGameModeBase code files (.cpp & .h): By default, an empty Project Game Mode Base is created. It's not usually used in most cases.
  • ProjectName.uproject file: Contains the descriptors used to provide basic information about the project and the list of plugins associated with it.

Debugging Code in Visual Studio

Visual Studio provides powerful debugging features with the help of breakpoints in code. It enables users to pause the game at a particular line of code so that the developer can see the current values of variables and step through the code and game in a controlled fashion (can proceed line by line, function by function, or so on).

This is useful when you have a lot of variables and code files in your game project, and you want to see the values of the variables being updated and used in a step-by-step fashion to debug the code, find out what issues there are, and solve them. Debugging is a fundamental process of any developer's work, and only after many continuous debugging, profiling, and optimization cycles does a project get polished enough for deployment.

Now that you've got the basic idea of the Visual Studio solution, we'll move on and cover a practical exercise on it.

Exercise 2.02: Debugging the Third Person Template Code

In this exercise, you'll be creating a project using the Third Person Template of Unreal Engine and will debug the code from within Visual Studio. We'll be investigating the value of a variable called BaseTurnRate in the Character class of this template project. We'll see how the value updates as we move through the code, line by line.

The following steps will help you complete this exercise:

  1. Launch Unreal Engine from the Epic Games Launcher.
  2. Click on the Games section and click Next.
  3. Select Third Person and click Next.
  4. Select C++, set the project name to ThirdPersonDebug, and click the Create Project button.
  5. Now, close Unreal Editor, go to the Visual Studio solution, and open the ThirdPersonDebugCharacter.cpp file:
    Figure 2.2: ThirdPersonDebugCharacter.cpp file location

    Figure 2.2: ThirdPersonDebugCharacter.cpp file location

  6. Left-click on the bar on the left-hand side of line 18. A red dot icon should appear on it (you can toggle it off by clicking on it again):
    Figure 2.3: Collision capsule init code

    Figure 2.3: Collision capsule init code

    Here, we are getting the capsule component (explained further in Chapter 3, Character Class Components and Blueprint Setup) of the character, which, by default, is the root component. Then, we are calling its InitCapsuleSize method, which takes in two parameters: the InRadius float and InHalfHeight float, respectively.

  7. Make sure the solution configuration setting in VS is set to Development Editor and click on the Local Windows Debugger button:
    Figure 2.4: Visual Studio build settings

    Figure 2.4: Visual Studio build settings

  8. Wait until you're able to see the following window in the bottom-left corner:

    Note

    If the window doesn't pop-up, you can open the window manually by opening Autos under Debug > Windows > Autos. Additionally, you may also use locals.

    Figure 2.5: Visual Studio variable watch window

    Figure 2.5: Visual Studio variable watch window

    this shows the object itself. The object contains variables and methods that it stores, and by expanding it, we're able to see the state of the entire object and its variables at the current line of code execution.

  9. Expand this, then ACharacter, and then CapsuleComponent. Here, you can see the values for the CapsuleHalfHeight = 88.0 and CapsuleRadius = 34.0 variables. Next to line 18, where the red dot initially was, you will see an arrow. This means that the code is at the end of line 17 and has not executed line 18 yet.
  10. Click the Step Into button to go to the next line of code (Shortcut: F11). Step Into will move into code inside the function (if present) on the line. On the other hand, Step Over will just execute the current code and move to the next line. Since there is no function on the current line, Step Into will mimic the Step Over functionality.
    Figure 2.6: Debug step into

    Figure 2.6: Debug step into

  11. Notice that the arrow has moved to line 21 and that the variables have been updated. CapsuleHalfHeight = 96.0 and CapsuleRadius = 42.0 are highlighted in red. Also, notice that the BaseTurnRate variable is initialized to  0.0:
    Figure 2.7: BaseTurnRate initial value

    Figure 2.7: BaseTurnRate initial value

  12. Step in (F11) once again to go to line 22. Now, the BaseTurnRate variable has a value of 45.0 and BaseLookUpRate is initialized to 0.0, as shown in the following screenshot:
    Figure 2.8: BaseTurnRate updated value

    Figure 2.8: BaseTurnRate updated value

  13. Step in (F11) once again to go to line 27. Now, the BaseLookUpRate variable has a value of 45.0.

Similarly, you are encouraged to step in and debug other sections of the code to not only familiarize yourself with the debugger but also to understand how the code works behind the scenes.

By completing this exercise, you've learned how to set up debug points in Visual Studio, as well as stop debugging at a point, and then continue line by line while watching an object and its variable's values. This is an important aspect for any developer, and many often use this tool to get rid of pesky bugs within code, especially when there's a lot of code flows and the number of variables is quite large.

Note

At any point, you can stop debugging, restart debugging, or continue with the rest of the code by using the following buttons on the top menu bar:

Figure 2.9: Debugging tools in Visual Studio

Figure 2.9: Debugging tools in Visual Studio

Now, we'll look at importing assets into an Unreal project.

Previous PageNext Page
You have been reading a chapter from
Game Development Projects with Unreal Engine
Published in: Nov 2020Publisher: PacktISBN-13: 9781800209220
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 $15.99/month. Cancel anytime

Authors (4)

author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry