Unreal Engine C++ Project Setup, From Scratch

Alex Forsythe
16 Jul 202030:46

Summary

TLDRThis video script offers a comprehensive guide to setting up and building Unreal Engine projects from scratch using just a text editor and command-line, bypassing the traditional Visual Studio workflow. It covers essential tools, project structure, and the build process, providing insights into the engine's inner workings. The tutorial aims to empower developers with a deeper understanding of Unreal projects, enabling them to diagnose and resolve issues more effectively.

Takeaways

  • ๐Ÿ›  You can create and work on Unreal projects using just a text editor and command-line tools, bypassing Visual Studio, which is the officially supported workflow but not the only way.
  • ๐Ÿ’ก The process of setting up an Unreal project from scratch can provide a deeper understanding of how the project structure and build system work.
  • ๐Ÿ–ฅ๏ธ For beginners, using Visual Studio's integrated development environment (IDE) is easy, but it might overshadow the opportunity to learn the underlying build system.
  • ๐Ÿ“ Essential tools for a developer include a text editor like Sublime Text 3 for coding and Cmder for a better command-line experience on Windows.
  • ๐Ÿ”ง Unreal Engine can be installed via the Epic Games Launcher, which simplifies the process of getting started with game development.
  • โš™๏ธ To develop in C++ with Unreal, Visual Studio is recommended, but it's important to match the version of Visual Studio with the one that Unreal Engine was tested against to avoid compatibility issues.
  • ๐Ÿ”— Understanding the relationship between project files, build processes, and how they integrate with Unreal's build system is crucial for troubleshooting and development.
  • ๐Ÿ“ The .uproject file and associated .Target.cs files are key to defining the project and its modules, which dictate how the Unreal Build System compiles the code.
  • ๐Ÿ”„ The build process involves generating source files, compiling object code, and linking into a DLL for the editor to load, which can be done without Visual Studio.
  • ๐ŸŽฎ After building, you can run the project in the Unreal Editor for testing and editing, or as a standalone game using cooked assets for a production build.
  • ๐Ÿ”ง Creating custom batch scripts can simplify the build process, making it easier to switch between coding and testing without the overhead of an IDE.

Q & A

  • What is the officially supported workflow for writing game code for Unreal Engine without using Visual Studio?

    -The officially supported workflow involves generating a solution file, opening it, and starting to write code. This approach is recommended for beginners as it's easy to start with.

  • Why might someone choose to not use Visual Studio for Unreal Engine projects?

    -Some developers might avoid Visual Studio due to personal preference or to gain a deeper understanding of how an Unreal project fits together and how the build system works.

  • What are the two essential tools every developer needs according to the script?

    -The two essential tools mentioned are a text editor and a terminal. Sublime Text 3 and Cmder are recommended for Windows.

  • How can a developer install Unreal Engine without using the Epic Games Launcher?

    -Developers can install Unreal Engine by cloning the complete Engine source from GitHub and building it themselves.

  • What is the recommended version of Visual Studio for C++ development with Unreal Engine 4.25?

    -For Unreal Engine 4.25, the recommended version of Visual Studio is 2017, as it includes the necessary Visual C++ 14.1 toolset.

  • Why is it important to check the release notes when setting up the build environment for Unreal Engine?

    -Checking the release notes ensures that you are using the versions of the tools that Epic Games has tested against for that specific release of Unreal Engine, which helps avoid build problems.

  • What is the purpose of the .uproject file in an Unreal Engine project?

    -The .uproject file defines the basic details about the project, including the source modules and the version of Unreal Engine it is built with.

  • How does the script suggest setting up a new Unreal project from scratch using a text editor?

    -The script suggests creating a project directory with a .uproject file, a Source directory with a module, and target rules files like .Target.cs to define how the project should be built.

  • What is the difference between building a project using Visual Studio and building it directly from the command line using Unreal's build system?

    -Building in Visual Studio essentially runs a batch file that invokes Unreal's build system. Building directly from the command line bypasses Visual Studio and calls the Unreal build system directly using Build.bat.

  • What is the purpose of cooking assets in Unreal Engine, and how does it differ from using uncooked assets?

    -Cooking assets is the process of converting them into a format suitable for the final game, such as compressing textures for faster loading at runtime. Uncooked assets are in their original, uncompressed form and are used during development in the editor.

  • How can developers automate the build process for their Unreal Engine projects?

    -Developers can create custom batch scripts that call Build.bat with the necessary arguments to build the project. This can be further automated by using variables and including common paths and commands in a separate script file.

Outlines

00:00

๐Ÿ› ๏ธ Unreal Development Without Visual Studio

The paragraph introduces the possibility of developing Unreal Engine games without using Visual Studio, suggesting that while it's a valid and beginner-friendly approach, it might cause developers to miss out on understanding the project structure and build system. The speaker proposes to demonstrate creating an Unreal project from scratch using just a text editor and command-line, aiming to provide a deeper understanding of the build process for troubleshooting purposes. The setup begins with a clean Windows installation, emphasizing the importance of having a text editor and terminal, and proceeds to install Sublime Text 3 and Cmder as preferred tools.

05:04

๐Ÿ“ฅ Installing Essential Tools for Unreal Development

This section discusses the installation of Unreal Engine and the necessary tools for C++ development. It presents two methods for setting up Unreal Engine: cloning the engine's source from GitHub or using the Epic Games Launcher, with the latter being chosen for its ease of use. The paragraph also covers the installation of Visual Studio, focusing on the specific versions required for compatibility with Unreal Engine, and the importance of matching the Visual C++ version and Windows SDK to avoid build issues. Additional components like the .NET Framework are also mentioned as necessary for certain Unreal tools.

10:05

๐Ÿ“ Setting Up a New Unreal Project Conventionally

The speaker outlines the standard workflow for creating a new Unreal project, which involves launching the engine and going through a user-friendly setup process that generates a project directory with necessary files and begins building from source. The project creation process is highlighted, including the generation of a Visual Studio solution file and the use of Unreal Editor's integrated tools for creating source files, such as adding a new C++ class, which automatically updates the project and compiles the new code.

15:08

๐Ÿ” Exploring Behind the Scenes of Unreal Projects

This paragraph delves into an alternative project setup that forgoes the beginner-friendly approach to reveal the inner workings of Unreal projects. It details setting up the development environment with Sublime Text and installing necessary plugins, creating a new project directory, and defining the project details in a .uproject file. The explanation continues with creating source modules, target rules files, and build rules files, emphasizing the cross-platform build system of Unreal and the independence from Microsoft's build system.

20:08

๐Ÿ—๏ธ Building and Running Unreal Projects from Source

The speaker explains the process of building an Unreal project directly from source using the command line, bypassing Visual Studio. It describes invoking the Build.bat file with specific arguments to build the project for a particular target, platform, and configuration. The output of the build process is detailed, including the generation of intermediate files, compiled object code, and the final DLL for the editor to load. The paragraph also explains how to open the project in the Unreal Editor using UE4Editor.exe and the significance of various directories and files generated during the process.

25:11

๐Ÿณ Cooking Assets and Creating Standalone Games

This section introduces the concept of 'cooking' assets in Unreal, which is the process of converting original, uncompressed data into a format suitable for runtime use by the game. It explains the difference between uncooked and cooked assets using a texture file as an example and describes the process of cooking assets for a Windows platform. The paragraph also discusses running a game using editor binaries versus a standalone executable, the latter requiring cooked assets. The process of creating a standalone game is outlined, including building a non-editor target and cooking content for a self-contained executable.

30:14

โš™๏ธ Automating the Build Process and Workflow Tips

The speaker provides insights on automating the build process with custom batch scripts to simplify the invocation of the build process and running the editor. Tips for an efficient workflow using Sublime Text are shared, such as setting up a project with directories, quickly browsing files, and using the engine source as documentation. The paragraph emphasizes the benefits of a fast and direct approach to coding, as opposed to relying on IntelliSense in Visual Studio, and concludes with a brief review of the entire build process covered in the script.

๐Ÿ™Œ Conclusion and Call to Action

The final paragraph wraps up the video with a thank you note for watching and an encouragement to share the knowledge with fellow Unreal developers. It invites viewers to engage in discussion through comments and emphasizes the value of genuine human connection in the community. The speaker reiterates the learning objective of the video and expresses gratitude for the viewers' time and interest.

Mindmap

Keywords

๐Ÿ’กUnreal Engine

Unreal Engine is a powerful game development platform widely used for creating 3D video games. It provides a complete suite of development tools, including a visual editor, a 3D engine, and a scripting language. In the video, the script discusses the process of setting up and building an Unreal project from scratch, emphasizing the engine's build system and project structure.

๐Ÿ’กVisual Studio

Visual Studio is an integrated development environment (IDE) from Microsoft, used primarily for Windows software development. It supports various programming languages, including C++. In the context of the video, Visual Studio is mentioned as the officially supported IDE for writing game code for Unreal Engine, although the script also explores alternative approaches.

๐Ÿ’กSolution File

A solution file is a file in Visual Studio that contains information about the projects in a solution and the relationships between those projects. It is used to manage multiple projects as a single unit. The script mentions generating a solution file for Unreal projects as part of the workflow for beginners.

๐Ÿ’กBuild System

A build system in software development is a set of tools and scripts used to automate the process of compiling source code into executable programs. In the video, the build system of Unreal Engine is discussed, explaining how it works and how developers can understand and interact with it directly.

๐Ÿ’กCommand-Line

The command-line is a text-based interface for interacting with a computer's operating system. It allows users to execute commands and perform operations without using a graphical user interface. The script demonstrates how to build and run an Unreal project from the command-line, bypassing the need for an IDE.

๐Ÿ’กText Editor

A text editor is a program that allows users to create and edit plain text files. It is a fundamental tool for programmers, as it provides a basic interface for writing and saving code. The video script recommends using a text editor like Sublime Text 3 for game development with Unreal Engine.

๐Ÿ’กC++

C++ is a general-purpose programming language known for its performance and flexibility. It is widely used in game development due to its power and control over system resources. The script discusses writing game code in C++ for Unreal Engine projects.

๐Ÿ’กSource Module

In the context of Unreal Engine, a source module refers to a collection of source code that is compiled into a dynamic-link library (DLL) or static library. The script explains how to create a source module for an Unreal project and how it fits into the overall build process.

๐Ÿ’กCooking Assets

Cooking assets in game development refers to the process of preparing and optimizing assets for the target platform, often involving compression and conversion to formats suitable for runtime use. The video explains the difference between uncooked and cooked assets, and how to cook assets for a standalone game build.

๐Ÿ’กBatch File

A batch file is a script file in DOS, OS/2 and Windows that contains a series of commands to be executed by the command-line interpreter. In the script, the creation of a custom batch file is discussed to simplify the process of building an Unreal project from the command-line.

๐Ÿ’กActor Class

In Unreal Engine, an Actor is a general class type that represents an object in the game world that can be manipulated through code. The video script includes an example of creating an Actor class, demonstrating the process of adding functionality to a game object.

๐Ÿ’กProject Configuration

Project configuration refers to the settings and parameters that define how a project should be built and run. These can include target platform, build type (e.g., Debug or Release), and other project-specific settings. The script mentions changing project settings like default map and target hardware settings.

๐Ÿ’กStandalone Game

A standalone game is a game that does not require the installation of an additional game engine or editor to run. It is a self-contained executable that includes all necessary game assets and code. The video script describes the process of creating a standalone version of an Unreal project.

Highlights

You can write game code for Unreal without Visual Studio by generating a solution file and writing code in any editor.

The officially supported workflow is beginner-friendly but might cause some to miss understanding the Unreal project structure and build system.

Visual Studio is not preferred by everyone, and an alternative approach using just a text editor and command-line is presented.

The video aims to provide a solid understanding of the build process to diagnose problems from error messages effectively.

A clean Windows installation is assumed for setup, including OS configuration and installing necessary drivers and utilities.

Every developer needs a text editor and terminal; Sublime Text 3 and Cmder are recommended for Windows.

Unreal Engine can be installed via cloning the source from GitHub or using the Epic Games Launcher for a simpler setup.

Visual Studio is required for C++ development with Unreal, and specific versions should be installed for compatibility.

The video demonstrates how to find the correct Visual Studio and .NET Framework versions needed for a specific Unreal release.

The recommended workflow for setting up a new Unreal project using the Unreal Editor is detailed.

Unreal's build system uses Visual C++ compiler and linker but does not rely on Microsoft's build system.

The video shows how to build a project directly from the command line without using Visual Studio.

Building a project results in various files including a DLL for the editor and a PDB file for debugging.

The editor can run a fully playable and editable form of the project using built editor binaries.

A standalone version of the project can be created by building a non-editor target which links against engine code to generate an executable.

Content must be cooked for a standalone game; this process compresses assets for runtime use on specific platforms.

The video presents a custom batch script to simplify the build process by automating the invocation of Unreal's build tool.

Workflow tips are provided, emphasizing the benefits of using a text editor like Sublime for fast browsing of code and engine source.

The video concludes with a review of the build process and the components involved in creating an Unreal project.

Transcripts

play00:00

You don't need to use Visual Studio to write game code for Unreal.

play00:04

You can generate a solution file, crack it open, and just start writing code.

play00:09

That's the officially supported workflow, after all, and it's a perfectly valid approach.

play00:13

In particular, it's great for beginners since it's an easy way to get started.

play00:18

But I've found it also leads a lot of people to miss out on an opportunity

play00:21

to form an understanding of how an Unreal project fits together and how the build system

play00:25

works.

play00:27

And let's face it, the Visual Studio Experience is not everybody's cup of tea.

play00:33

So in this video, I'm going to show you how we can make an Unreal project from scratch,

play00:37

with just a text editor, and how we can build and run that project from the command-line.

play00:43

My hope is that you'll come away from this video with a solid, baseline understanding

play00:47

of what happens when you build your project, so that down the line, when something goes

play00:51

wrong

play00:52

and you're staring at a wall of cryptic error messages, you'll have a better idea

play00:54

of how to diagnose the problem and get moving again.

play00:58

Just so we're all on the same page, we're going to start from a clean installation of

play01:02

Windows.

play01:03

So we need to do some initial setup: this means configuring the OS to suit our tastes,

play01:07

deleting all the garbage that comes preinstalled,

play01:13

installing whatever drivers and utilities we need...

play01:16

and deleting even more garbage for good measure.

play01:18

Now, before we start talking about game engines and compilers,

play01:21

there are two essential tools that every developer needs:

play01:25

a text editor and a terminal.

play01:27

I'm going to install my favorites for Windows, which are Sublime Text 3 and Cmder.

play01:31

Sublime Text is great because it doesn't get in your way.

play01:34

It's highly customizable and packed with great features,

play01:37

but it's also extremely lightweight and responsive.

play01:40

No matter how big your codebase is, Sublime won't slow down and it won't hang.

play01:44

Cmder is a package that's built on top of ConEmu to provide a better command-line experience

play01:49

on Windows.

play01:51

Once we've got it up and running, we can press Ctrl+~ at any time to show or hide our terminal.

play01:57

Now we have our two most essential tools.

play01:59

We'll see them in action in a little bit.

play02:01

But first, let's install Unreal.

play02:03

There are two ways to set up an installation of Unreal Engine:

play02:07

you can clone the complete Engine source from GitHub and build it yourself,

play02:11

or you can install a pre-built version using the Epic Games Launcher.

play02:15

If you want to be able to make changes to the Engine itself,

play02:18

cloning and building from source is the way to go.

play02:22

But the Launcher makes it easy to get up and running, so that's what we'll use for now.

play02:25

We just need an Epic Games account, and then we can install and run the launcher,

play02:29

go to Unreal Engine -> Library, and install the latest version of Unreal.

play02:33

This download is about 12 gigs, and it'll end up taking up about 35 gigs once installed.

play02:38

After the download finishes, it'll verify everything,

play02:41

prompt us for permission to install prerequisites, and then we're good to go.

play02:47

Since we're going to be writing game code in C++, we need to install Visual Studio.

play02:51

Most people should just install the newest version of Visual Studio

play02:54

that's recommended for their release of Unreal and move on.

play02:58

But we aren't most people, so we're going to pay attention to specific versions.

play03:02

And Visual Studio versions can be a bit confusing.

play03:05

Essentially, the Visual Studio IDE is its own product, with its own sequential versioning

play03:10

scheme,

play03:11

and each major version is branded with a release year.

play03:15

But then there are different languages, each with their own runtimes and build tools,

play03:18

that you can use in conjunction with Visual Studio.

play03:21

For C++ development, you use Microsoft Visual C++ (MSVC)

play03:26

and it has its own versioning scheme separate from the Visual Studio IDE.

play03:31

So we want to build our project with Visual C++ 14.1,

play03:35

which means we want to install, at a minimum, Visual Studio 2017.

play03:40

So how do we know which version we need?

play03:43

If we look up the release notes for the version of Unreal that we're using,

play03:45

and we find the heading "IDE Version the Build farm compiles against,"

play03:49

we'll see what versions are officially supported.

play03:52

These may not be the latest versions, but they're what Epic tested against for this

play03:56

release.

play03:57

It's not a hard requirement that we use these exact versions,

play04:00

so if you already have newer versions installed and everything works fine for you,

play04:04

you don't have to downgrade to an older version.

play04:07

But when you're working on a team, making sure that everybody

play04:09

has the same version of the build tools is a good way to avoid build problems.

play04:13

Since I'm setting up a new machine and I intend to work with 4.25, I'm going to stick to these

play04:17

versions.

play04:19

So we'll want to find the installer for the major product version of Visual Studio,

play04:22

which is 2017 in this case.

play04:25

The community edition is free and has everything we need.

play04:28

The Visual Studio installer presents you with a choice of workloads,

play04:31

which will install different sets of tools based on the languages and platforms you'll

play04:35

be working with.

play04:37

For Unreal development, you need the "Desktop development with C++" workload:

play04:42

this will install the traditional Visual C++ toolset,

play04:45

including the compiler, linker, and build tools, the debugger, and the runtime and platform

play04:49

SDKs.

play04:51

It's also a good idea to grab the .NET workload as well:

play04:54

a lot of Unreal's external tools are written in C#, including the Unreal build system itself,

play04:59

so if you ever end up needing to build those from source, the .NET tools will come in handy.

play05:04

The release notes mentioned a specific version of the .NET Framework:

play05:07

we need this exact version of the targeting pack in order to run any builds.

play05:11

We can find that version in the list of individual components and make sure it's installed.

play05:16

We can also check to see how closely we're hewing to our target version of Visual C++.

play05:20

According to the release notes, we want Visual C++ version 14.16:

play05:24

we're at the same major and minor versions here, so we should be good to go.

play05:30

We also need the Windows SDK, and the latest version

play05:33

that this installer offers is older than our target version.

play05:37

So we'll go with this one for now, but we'll take the extra step

play05:39

of installing an updated Windows SDK once this is done.

play05:44

Now we can start the install and let it run.

play05:48

When it's finished, we can boot up Visual Studio.

play05:52

Great.

play05:53

As an extra step, I'm going to grab the latest release of the Windows 10 SDK version that

play05:58

4.25 was tested against.

play06:00

Note that Windows SDK releases are typically pegged to Windows 10 OS Updates,

play06:05

so you may need to run Windows update before installing a new SDK.

play06:09

And if you previously installed Visual Studio without the required .NET targeting pack,

play06:14

you can download and install that separately after the fact.

play06:18

So now we've got Unreal Engine installed,

play06:20

along with all the required tools to build C++ projects from source.

play06:25

Let's take a look at the conventional, recommended workflow for setting up a new project.

play06:30

When we first launch the engine, we'll be prompted to create a new project.

play06:33

We can start from a template, but we'll just make a blank project.

play06:37

We'll make sure we're using C++, we'll disable starter content,

play06:41

and we'll just use the default name and path for now.

play06:45

When we create the project, Unreal generates a new project directory

play06:48

and populates it with a .uproject file as well as Config, Content, and Source directories.

play06:55

It generates a Visual Studio solution for us, and it begins building our project from

play06:58

source.

play07:02

When it's done, we end up with an editor DLL for our project,

play07:05

and the editor then loads that module and opens the project.

play07:09

This is a great way to get a new user up and running:

play07:12

we just had to go through one straightforward, user-friendly setup process,

play07:16

and now our project is fully up and running.

play07:19

Unreal Editor also has some integrated tools for creating source files,

play07:22

which are similarly great for making the development process discoverable to beginners.

play07:27

If we want to add a new class, we can choose New C++ Class from the menu.

play07:32

Let's just make it an Actor class, and sure, we'll just call it MyActor.

play07:37

Unreal will create the source files, update our Visual Studio project,

play07:41

compile and reload the project DLL, and bring Visual Studio to the foreground.

play07:46

So we've got some nice boilerplate here, with handy comments so we'll never forget what

play07:50

"Tick" means,

play07:52

and with some kinda sloppy whitespace, and... a... copyright notice, for some reason?

play07:58

And of course, we can build our project straight from Visual Studio.

play08:02

By the way, at the top of the build output here is where we can verify

play08:05

that Unreal's build system is using the expected versions of the Visual C++ toolchain and the

play08:10

Windows SDK.

play08:12

So that's the officially recommended workflow.

play08:15

And it works!

play08:16

It's fine!

play08:17

It's meant to make this process accessible, and it does a great job at that.

play08:20

But I want us to take a look behind the curtain

play08:22

to see how all these project files and build processes relate to each other.

play08:27

So as an alternative to the beginner-friendly approach, here's my new project setup workflow.

play08:33

First, let's get Sublime set up.

play08:36

Hitting Ctrl+Shift+P brings up the command palette.

play08:39

We can run "Install Package Control" to get a built-in package manager,

play08:43

which we can then use to install a few plugins.

play08:45

I recommend grabbing Project Manager and Switch File Deluxe.

play08:50

I've created a package called Unreal Snippets that I'd recommend as well:

play08:54

if you don't see it in Package Control, you can run "Browse Packages" to open your package

play08:58

directory,

play08:59

then you can download the snippets from GitHub and place them there.

play09:04

Now let's make a project.

play09:05

Hit Ctrl+Shift+P again, and use Project Manager to add a new project.

play09:11

When it comes to naming your projects, my advice is: don't overthink it.

play09:14

You don't need this name to be a part of your public-facing brand,

play09:17

and it doesn't even need to describe the game you're trying to make.

play09:20

I recommend using a single short codename.

play09:23

I'm just going to call my project "Dirk."

play09:26

Next we'll create a workspace directory:

play09:28

this will contain any Unreal projects we create, along with any associated tools, scripts,

play09:32

assets, or other files.

play09:34

For me, this will be E:\hobby.

play09:38

We can use the command palette to add that directory to our current project.

play09:42

So now let's make ourselves an Unreal project from scratch.

play09:45

The first thing we need is a project directory.

play09:49

We need a .uproject file to define the basic details about our project.

play09:53

We'll populate this file in a second.

play09:55

And we'll need a Source directory as well:

play09:57

this is where our project's C++ source code lives.

play10:01

The project's codebase can be split into multiple source modules.

play10:04

To start with, we'll just have a single module, and we'll call it DirkCore,

play10:08

since it'll contain the core gameplay classes for our Dirk project.

play10:12

So, back to the .uproject file.

play10:16

Since we've installed Unreal Snippets, we can just type "uuproj" and hit Ctrl+Spacebar

play10:20

to populate the file.

play10:22

The one thing we need to fill in is the name of our first source module, which we're calling

play10:25

DirkCore.

play10:28

Next we need to go to the root of our Source directory,

play10:30

where we'll create a file called Dirk.Target.cs.

play10:34

We can add in the boilerplate here with "umt".

play10:38

This file is a target rules definition:

play10:40

it tells the Unreal Build System how to build our project.

play10:44

The main thing we need to specify is which source modules should be built for our target:

play10:48

so for right now, we'll add DirkCore to this list.

play10:53

We also need another target rules file for our Editor target.

play10:56

This'll be called DirkEditor.Target.cs, and it's populated the same way,

play11:01

we just need to make sure the target type is set to Editor.

play11:05

So the .uproject file tells Unreal Editor that it can open this directory as an Unreal

play11:10

project using 4.25,

play11:13

and it additionally specifies that when the Editor opens this project,

play11:16

it should find and load the compiled DLL for the module called DirkCore.

play11:21

The .Target.cs file tells the Unreal Build System that it can build all the necessary

play11:25

code

play11:26

for this project by building the DirkCore module.

play11:30

So let's add the source for that module.

play11:32

It's a fairly common convention in Unreal to split a module's Source into Public and

play11:36

Private subdirectories:

play11:39

Public contains the headers that need to be visible to other modules,

play11:42

and Private contains implementation files and any code that's internal to the module.

play11:46

We'll need one more C# file, this time in the module directory itself:

play11:52

DirkCore.Build.cs.

play11:54

The snippet to use here is "umb".

play11:57

This is a module build rules file, and it tells the Unreal Build System how to build

play12:01

this module for the target that it's currently building.

play12:04

The main thing here is the list of other modules that this module depends on:

play12:09

currently we have access to the core set of Engine functionality

play12:12

defined in these three modules: Core, CoreUObject, and Engine.

play12:17

If we look at the Engine's Source directory, we can see that it's organized by module type.

play12:22

The Runtime modules represent all the first-party engine code that can be built into your final

play12:27

game executable,

play12:29

leaving aside the editor and development tools.

play12:32

Within that directory, we can see all the different runtime modules that make up the

play12:36

Engine.

play12:37

What our build rules file is essentially saying is that DirkCore depends on these three modules:

play12:43

when we write code in DirkCore, we can use any of the functionality that's defined in

play12:47

these modules.

play12:49

If we need to call functions from a different module, then we'd need to add that module

play12:52

as a dependency.

play12:54

For example, if we were making a VR game and we needed to access the HMD directly,

play12:58

we'd add the HeadMountedDisplay module to our module's list of dependencies.

play13:04

So we've set up everything that the build system needs:

play13:07

now we just need to write some code for it to build.

play13:09

At the bare minimum, every module needs to have a module definition,

play13:13

which is typically in a source file with the same name as the module.

play13:17

We'll start by adding a public header called DirkCore.h.

play13:21

To get the boilerplate, we can use "umh" here - unreal-module-header.

play13:26

This defines the entry point for our module:

play13:28

Unreal will call StartupModule after loading it, and it'll call ShutdownModule just before

play13:33

unloading it.

play13:35

Now we can make a corresponding DirkCore.cpp file, and here we'll run "umcp" for unreal-module-cpp-primary.

play13:44

This registers our module implementation as the primary module for our game.

play13:49

Each project needs exactly one module that's designated as the primary game module.

play13:54

We'll also add a log category that's specific to our module.

play13:58

It'll be internal to DirkCore, so we can add Log.h and Log.cpp to our module's Private

play14:04

directory.

play14:05

"ulh" gives us the boilerplate for the header, and "ulc" fills out the implementation.

play14:11

So now, from any .cpp file in our module, we can include Log.h,

play14:15

and that'll let us add log output using the "ull" snippet (unreal-log-line).

play14:21

This'll show up in the console output and the log files for our game,

play14:25

and we can filter by our category (LogDirkCore) to get output from this module specifically.

play14:32

So now that our primary module is defined, we have a project that's ready to build from

play14:36

source.

play14:37

We've done all this without Visual Studio or Unreal Editor:

play14:40

not because those are inherently bad tools,

play14:43

but just because this approach gives us a chance to see what's happening under the hood.

play14:48

Unreal uses the Visual C++ compiler and linker,

play14:51

and it recommends Visual Studio as an officially supported IDE,

play14:55

but it doesn't actually use Microsoft's build system.

play14:58

Instead, Unreal has its own cross-platform build system,

play15:02

which is why we need to write those C# files to configure our target and its modules.

play15:07

When you generate Visual Studio project files,

play15:10

those solution and project files aren't actually an essential part of the build:

play15:13

they're just a Visual-Studio-compatible frontend for Unreal's build process.

play15:19

If we look at our Engine directory again, under Build/BatchFiles,

play15:22

we can see a file called Build.bat.

play15:25

This basically just calls UnrealBuildTool.exe, which invokes builds.

play15:31

When you build your project in Visual Studio, it's essentially just running this Batch file.

play15:35

So let's leave Visual Studio out of the equation and see how we can build our project directly.

play15:41

All we have to do is invoke Build.bat and pass in a few things.

play15:45

We need to tell it which Target we want to build,

play15:48

then we need to give it a platform and a build configuration:

play15:51

our platform is going to be Win64 for editor targets on Windows.

play15:55

For the build configuration, we'll use Development,

play15:58

which is sort of a middle ground between a Debug build and a Shipping build.

play16:03

Then we just pass in the path to the .uproject file, and we can kick off the build.

play16:09

Once the build gets going, we start getting build artifacts in the Intermediate directory,

play16:13

starting with some files spit out by the build system.

play16:16

Eventually, Unreal Header Tool parses our source and spits out generated source files,

play16:22

then everything gets compiled to object code,

play16:24

and then finally our module is linked together into a DLL that the editor can load.

play16:29

We can see that DLL in the Binaries directory:

play16:32

this file contains all the code we've written in our DirkCore module, in a compiled binary

play16:37

form.

play16:39

Next to that is the corresponding PDB, or symbol file:

play16:43

this essentially contains debugging information so that symbols in the compiled binary version

play16:48

of our code

play16:49

can be traced back to the corresponding functions, variables, and other identifiers in the source

play16:53

code.

play16:55

We also get a .modules file, which is just a bit of metadata telling the editor which

play16:59

DLLs should be loaded for this module,

play17:01

and which Engine version those DLLs were compiled against:

play17:05

this is why you'll get an error if you build editor binaries on one version of Unreal,

play17:09

then try to open them with a different version.

play17:12

There's also a .target file, which is just more metadata spit out by the build system.

play17:17

So now that we've built the one module that our project needs to load,

play17:20

we can open the project in the editor.

play17:23

To do that, we just run UE4Editor.exe from our engine installation,

play17:27

passing in the path to our .uproject file.

play17:31

Since this is our first time booting up the project,

play17:33

we can see the Editor writing out some new files in our project directory.

play17:37

Once the editor boots up, we're up and running.

play17:42

We can save a new map file in the Content Browser,

play17:44

and let's make a quick adjustment just so this map looks different from the template.

play17:49

Now if we look at our project settings, we can generate a unique ID for the project,

play17:53

and we can also set our target hardware settings.

play17:56

We'll also change our default map to the one we just saved.

play18:01

Let's look at our project directory now.

play18:03

We still have our .uproject file and our Source directory,

play18:06

as well as the Binaries that we've built for the project.

play18:09

We've now also got a Saved directory,

play18:11

which contains logs and other files created at runtime,

play18:14

either by the game or the editor.

play18:17

We've got DerivedDataCache, where the editor can cache data that it's built for imported

play18:21

assets,

play18:22

and we've got a Content directory, which maps directly to our project's assets in the Content

play18:26

Browser.

play18:27

Finally there's the Config directory, where our project configuration changes have been

play18:31

stored in .ini files.

play18:34

So that's the editor up and running.

play18:36

We've built editor binaries for our project,

play18:39

so we're able to load our project in a fully playable and fully editable form using UE4Editor.exe.

play18:43

We can also launch a playable game instance using editor binaries,

play18:49

without loading up the editor itself.

play18:51

To do that, we just pass in the -game flag at launch.

play18:55

This is a fully playable instance of our game.

play18:57

We can fly around, we can use console commands, and we can run "exit" when we're finished.

play19:04

So that's a quick way to test out the game in a development setting:

play19:07

we're running from editor binaries, but that means we need this full installation of Unreal

play19:11

Engine in order to run this build.

play19:13

If we want a standalone version of our project, that's what our non-editor target is for.

play19:19

All we have to do is invoke the same build process,

play19:22

passing in our project's Game target instead of its Editor target.

play19:26

This'll run through the same build process, but instead of linking our individual modules

play19:30

into DLL files,

play19:31

it'll link our project against all the required Engine code and generate a single executable

play19:36

that runs our game, with all the editor-specific functionality stripped out.

play19:40

You can see that our game executable is much larger than our editor DLL,

play19:44

since it's a self-contained binary.

play19:46

But we can't run Dirk.exe just yet: first we need to cook content.

play19:52

To make sense of the difference between cooked and uncooked assets, let's use a texture file

play19:57

as an example.

play19:59

When we import an image file into the Editor, we end up with a Texture2D asset,

play20:03

which is stored in our Content directory as a .uasset file.

play20:08

This uncooked asset contains the original uncompressed image data for our texture,

play20:12

along with all the flags and other property values we've set after importing.

play20:16

In short, the uncooked asset is everything the editor needs:

play20:19

it contains the original data in a complete and nondestructive form.

play20:24

The final game, on the other hand, doesn't need the uncompressed image data;

play20:28

it needs a compressed texture that it can load straight into the GPU.

play20:31

This is the cooked form of the asset: it's the same asset,

play20:34

but prebuilt for a specific platform, with only the data that's necessary at runtime.

play20:41

So when we import this Targa, we get an uncooked Texture2D asset that contains the original

play20:46

image data.

play20:48

When we cook the asset for Windows,

play20:50

we get a cooked asset file containing DXT-compressed image data that the game can load at runtime.

play20:56

To cook data for our project, we can run the command-line version of the editor,

play21:01

passing it our project file and telling it to run the cook commandlet,

play21:04

with the target platform set to WindowsNoEditor.

play21:08

When that's done, we end up with a Saved/Cooked directory:

play21:12

this is where our standalone game executable will find all the assets it needs to load

play21:15

at runtime.

play21:19

So now we can run our game: this should be functionally the same as running from editor

play21:24

binaries,

play21:25

except we're now using cooked data loaded straight from disk:

play21:28

the engine isn't building any assets on demand at runtime.

play21:32

We've still built in the Development configuration, though,

play21:34

so we have access to all the same developer tools.

play21:38

So, sure, we don't need to use Visual Studio to build a project.

play21:44

That's cool and all, but having to invoke this batch file with these specific arguments

play21:47

is kind of a pain in the ass.

play21:50

One quick fix is to make our own batch script that invokes this build.

play21:54

If we just write this command into a file called build.bat...

play21:57

then we can just enter "build" to build our project.

play22:02

Batch files aren't really the state of the art in build automation,

play22:05

but we're not doing anything fancy here, and this approach works fine.

play22:08

We can make a few quick improvements, though.

play22:11

We can add "@echo off" to keep our commands from being printed out.

play22:15

And then we can build these paths a little more procedurally, if we want to.

play22:19

You might remember that "%~dp0" in a batch script gives you the directory of the script

play22:24

file.

play22:25

You're probably not going to remember that :~0,-1 will strip the trailing slash from

play22:31

that path,

play22:32

so you'll have to Google it like the rest of us.

play22:35

But anyway, we can make the project name a variable, then build up the path to our .uproject

play22:39

file,

play22:40

and then do some substitution in the command.

play22:45

We can do the same thing to construct the path to Build.bat based on where our Engine

play22:48

version is installed.

play22:50

So now we have a script that calls Build.bat for the Editor target of our project.

play22:54

And if we run build - it does the same thing.

play22:57

Cool.

play22:58

We can make a similar script called editor.bat to run the editor.

play23:03

And instead of duplicating all these batch variables,

play23:05

we'll just factor them into a file called vars.bat.

play23:09

And then we can also build the path to UE4Editor.exe.

play23:12

So now editor.bat is largely the same as build.bat; we just invoke a different command.

play23:19

With these two scripts, we can run "build" to build our project,

play23:23

and we can run "editor" to launch the editor.

play23:25

Our editor script will also forward any additional arguments to the editor on launch.

play23:31

What's great about using the command-line is that we can easily chain multiple commands

play23:34

together.

play23:35

If we run "build && editor", that'll build, and then if and only if the build succeeds,

play23:41

it'll launch the editor.

play23:43

This lets us jump back and forth between code and editor really quickly.

play23:48

Let's add a new actor just to demonstrate the workflow.

play23:52

We're going to add a new header file to our DirkCore module and call it TestActor.h.

play23:57

The "uca" snippet will define an Actor class.

play24:02

We can use "upc" to add a component property:

play24:05

we'll make it a billboard component, which just displays a sprite.

play24:09

We can use "upe" to add an editable property.

play24:13

This'll just be an arbitrary value so we have something to test.

play24:17

Finally, we'll override BeginPlay, and we'll declare a constructor.

play24:23

That's it for the header - now we can make a corresponding .cpp file and include our

play24:27

header.

play24:28

I'm using Alt+O to switch between the header and the source file.

play24:32

Let's grab these two functions and implement them.

play24:37

We're going to construct a root SceneComponent and a BillboardComponent,

play24:41

so let's add those to our engine includes.

play24:44

Then we'll use the ObjectInitializer to create both components,

play24:47

with our billboard component attached to the root.

play24:50

And then we can assign a default value to our property.

play24:55

Finally, let's make the actor do something at runtime.

play25:00

We're just going to have it write a line of log output, so we'll include our module's

play25:04

private log header.

play25:06

Then in the body of BeginPlay, we can use the "ull" snippet to add a log line.

play25:10

We'll write out the name of the actor, and then the integer value of our property.

play25:16

So now that we're ready to test our changes, here's our iteration loop:

play25:20

Ctrl+Tilde to bring up the console...

play25:23

Up arrow to retrieve the last command we ran...

play25:25

And Enter to run.

play25:27

Now, if there are no errors, the editor will appear and we can test our changes.

play25:31

If the build fails, it'll halt instead.

play25:34

So here we have an error on line 16 of TestActor.cpp, and if we go there...

play25:39

Hah, "sprote."

play25:40

...we can fix our typo.

play25:44

And then same thing again: Ctrl+Tilde, Up, Enter.

play25:47

This time, the build is good and we go straight to the editor.

play25:52

We can place an instance of our actor,

play25:54

we can see that its Value property defaults to 42,

play25:57

we can change the value on this instance,

play25:59

and if we run the game, we can see our line in the log output.

play26:05

So that's my workflow.

play26:06

A lot of these choices come down to personal preference.

play26:09

You don't have to use these exact tools if something else works better for you.

play26:13

But I wanted to point out that there's more than one way to do this part of the job,

play26:17

and more importantly, I thought it'd be a good opportunity to look a bit deeper at how

play26:20

an Unreal project is structured.

play26:22

Before we wrap up with a quick review of the build process, here are a few just workflow

play26:26

tips:

play26:28

I'd recommend setting up your Sublime project with your project's Config and Source directories.

play26:34

If you hit Ctrl+P, you can quickly browse to any file that's been included in the project.

play26:40

If we add UE4's Engine/Source/Runtime directory, then we'll also have the Engine source at

play26:45

our fingertips.

play26:48

Since we've installed Switch File Deluxe, we can use Alt+O to jump between header and

play26:51

source files.

play26:53

Highlighting a symbol and pressing F12 will instantly jump to where that symbol is defined.

play26:59

The key distinction here is that where Visual Studio tries to be smart, Sublime just tries

play27:03

to be fast.

play27:05

With Visual Studio, you're dealing with IntelliSense,

play27:07

which has to parse the entire Engine codebase and run extensive static analysis,

play27:12

and then it has to reason about that codebase while working around the fact

play27:15

that huge chunks of it rely on a custom code generation process...

play27:19

and if you ask me, expecting it to be reliably correct and responsive is just too much to

play27:24

ask.

play27:25

Back when I was using Visual Studio, I found I couldn't rely on IntelliSense,

play27:29

and I'd end up just searching through the API documentation all the time.

play27:33

But the code itself contains the exact same documentation:

play27:36

you can cut out the middle-man and Ctrl+P your way straight to an answer,

play27:40

faster than it takes for an IntelliSense completion window to appear.

play27:43

This approach keeps you in the driver's seat.

play27:45

We can use Ctrl+Shift+F to search the entire codebase to see how a symbol is used or referenced.

play27:53

And another good source of example code is the Engine Plugins directory.

play27:57

If we limit our search there, we can find usage examples that are set up in the same

play28:01

way our project code should be.

play28:03

I've found that if you treat the Engine source as documentation in and of itself,

play28:08

and if you optimize your workflow for browsing that source,

play28:11

you'll gain a much more intuitive understanding of it over time.

play28:14

For example, if I can't remember exactly how to update an actor's transform,

play28:18

I can just flip straight over to Actor.h and find the function signature.

play28:23

Once I've done that a couple of times, I know it by heart:

play28:25

I don't need to keep looking at documentation or waiting on IntelliSense to tell me.

play28:31

So that concludes the opinion portion of our program.

play28:34

Before we go, let's just briefly review what we've accomplished here.

play28:38

We've installed Visual C++ as part of Visual Studio, giving us a compiler and linker.

play28:44

We've also installed Unreal, giving us access to all the Engine tools.

play28:48

Then we created a new project.

play28:50

If our project were Blueprint-only, then our .uproject file wouldn't specify any additional

play28:55

modules,

play28:56

so we'd just be able to load it up in the editor straightaway.

play28:59

However, when a project has its own source modules,

play29:02

the editor needs to load the DLLs for those modules in order to open the project.

play29:07

If we want to build those DLLs ourselves, our project needs a source directory.

play29:12

Within the source directory, we can have one or more modules,

play29:15

each with a Build.cs file along with its C++ source.

play29:19

The project itself needs a .Target.cs file to tie all the modules together.

play29:24

When we build our project, UnrealBuildTool looks at our target rules

play29:27

and figures out which modules it needs to build from source.

play29:32

Then it goes about building those modules, based on how their build rules are configured.

play29:37

First it invokes UnrealHeaderTool to parse the headers and write out generated code.

play29:42

Then it runs the compiler for each translation unit, giving us compiled object code for each

play29:46

.cpp file.

play29:49

Finally it links all of the module's code together,

play29:50

resolving any cross-module references based on the list of dependencies in the build rules.

play29:57

Once the build is done, we're left with the editor binaries.

play30:00

Along with the .uproject file, this lets us edit or play our project in the editor, using

play30:04

uncooked content.

play30:06

We can also use the editor, running from the same binaries, to cook content.

play30:10

And once that's done, we're able to run our standalone game.

play30:14

And that's it!

play30:15

Thanks for sticking with me here, and I hope you learned something.

play30:18

If you know an Unreal developer who might appreciate this video:

play30:20

please, give them a call, see how they're doing, coming from a place of genuine curiosity

play30:24

and care,

play30:26

and then link them to the video.

play30:27

That would mean a lot to me.

play30:29

And if you, a decent human being, have any questions for me, a decent human being:

play30:34

or if you'd like to discuss the points raised in this video with other decent human beings

play30:37

like yourself...

play30:38

then please, feel free to comment below, like a decent human being.

play30:42

Thanks for watching!

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
Unreal EngineGame DevelopmentC++ CodingVisual StudioBuild SystemCommand-LineCustom WorkflowProject StructureSource ModulesCross-Platform