How to Build the FPS C++ Project with Unreal Engine 4
Learn how to build a first-person shooter project with Unreal Engine 4 in this article by Matt Edmonds, a gaming enthusiast and a professional game maker for PC, console, and mobile since 2000.
Building the FPS C++ project
This article will take you through the steps of creating a new project from scratch using the Unreal Project Browser. For anyone new to this setup, there are some necessary steps to getting started. You’ll need the following components:
In the next section, you’ll do some modifications to the game mode and player, recompile these, and see the results in-game. There are three major steps to getting a brand new project up and running:
Installing and building UE4
Your first step is to download the UE4 source code and build it. This can be done in a number of ways. The simplest way is to go to their GitHub site to acquire the engine, at https://github.com/EpicGames/UnrealEngine. For the link to work, you must be signed in to GitHub, and have applied as an Unreal Developer. See https://wiki.unrealengine.com/GitHub_Setup for details.
Click on the
Clone or download button to see your options. From here, the simplest solution is to select the option to download the project as a ZIP file and unzip it wherever you like on your hard drive, as shown in the following screenshot:
You can use SourceTree, a free app, for managing GitHub projects. For those comfortable with command-line work, there are a number of options, as well as a terminal that you can open in order to use these commands in SourceTree. Now, get the UE4 tree installed to start building!
The first thing to do when downloading a new version of the engine, be it an update or fresh install, is to always run
Setup.bat (or the
setup command on Mac) in the main installation folder before taking other steps. Make sure that the pop-up window is getting all the platforms you use, ensuring that it pulls the required files for the platform that are described in the
README.md file in the same folder.
setup command has completed, run the
GenerateProjectFiles.bat file, and a
UE4.sln file will appear in the same folder. A quick note on the state of UE4-generated solutions and VS 2015 and VS 2017: UE4 generates VS 2015 project files by default. It is possible to specify
-2017 as a batch file argument. It is currently not necessary to build for 2017, and the 2015 project files open, build, and run perfectly well in both VS 2015 and VS 2017. However, if you have both versions of VS installed, then by default it will try to open them in VS 2015.
Now, follow these steps:
.slnand open it in VS.
Set as Startup Project.
Development Editoras the
Running the editor and picking a template
The next step is to run the editor. Launch the engine in VS by pressing F5. Without a game or app project in the solution, this will take you directly to the Unreal project browser. You can also easily do this any time later by right-clicking on the UE4 project in the solution explorer and debugging or running it directly.
It’s also recommended to simply create a shortcut to your UE4 install folder's
/Engine/Binaries/Win64/UE4Editor.exe file, as it can sometimes be beneficial to quickly launch this outside your programming IDE. From the Project Browser, go through the following steps:
New Projecttab, and under it, the
First Personicon as your type to make your first-person shooter (FPS) base.
The choices for
Starter Content can be left as their defaults, but feel free to hover over them and click their drop-down arrows to see the options for each, as well as the brief descriptions of what they do.
At this point, UE4 will close the project browser, generate the game's project files, and attempt to open it in VS. It is a good idea to simply close the engine-only IDE session, as the engine project is also opened in the project solution. The project should now be the startup project and should contain several source files for the C++ template.
Building and running the game project
Now, you can finally build and run your game. Building the FPS sample project should go very quickly, and unless you change to another configuration or platform, it will not require building the engine code again. As a general rule, it is a good idea to build DebugGame versions for testing. Using this, you will get some extra runtime information and safety checks for your project's code, but typically without a significant change to performance when testing.
DebugGame Editor, as a standalone configuration (DebugGame) running on your PC, will build only the game project's code in debug but continue using the engine in its faster-running development configuration.
Changing the configuration to Debug Editor, for example, would force the engine to fully build in debug as well. The engine runs rather slowly in areas in debug builds. Also, maintaining both debug and development builds of the engine is time-consuming and usually unnecessary, unless it is actually debugging the engine code directly.
Once the project finishes building, simply run it using F5. This will launch the editor with your game as the game project. The editor in UE4 is where all developers, including programmers, will do a huge amount of work and testing while building a game or app. Play In Editor (PIE) is one of Unreal's greatest strengths, as is the hot-reload of the game library while working in the editor.
As projects grow in complexity and the game flow may change from the simple starting of a level, hot-reloads and PIE itself may not always be a viable option for testing. But, here, it is perfect for showing off some of its advantages. Generally, when working on gameplay systems or debugging new code, PIE will be your best friend.
Feel free to give it a shot with the
Play button near the right side of the top bar of the editor's default layout. Immediately, you'll notice that you can move around with the traditional WASD FPS keyboard controls, fire a weapon (with some physics impact on its projectile when it hits the cubes in the level), and even jump with the spacebar.
At this early stage, it is always a good idea to consider your controls. It is recommended that you maintain viable PC controls for any game type for any team to use while working in the editor and PIE. Even if a game or app will not use a PC as its native platform, such as those using a mobile or VR, the speed and ease of testing in PIE makes maintaining parallel PC controls very valuable.
In fact, if you go to the game project, open the
MasteringCharacter.cpp file, and browse through some of the input code, you will notice that it specifically supports two methods of turning in order to correspond to a control stick or virtual control stick on mobile, as well as direct axis input, such as a mouse.
There is also commented-out code to support the one-touch movement and turning on a touch-screen device, such as a phone or tablet. You can browse the existing inputs to see what was already set up and bound across the various platforms. Just keep in mind that at a time like this, it is typically much easier to begin maintaining controls across multiple platforms earlier than it is to add controls for a whole platform later.
If you found this article interesting, you can explore Mastering Game Development with Unreal Engine 4 - Second Edition to master all major UE features and bring self-imagined games to life through Unreal Engine 4.18+. Mastering Game Development with Unreal Engine 4 - Second Edition is a comprehensive guide with coverage on AudioFX, Particle system, shaders, sequencers, and the latest features of Unreal 4.19 that will take your game development skills to the next level.
Please login to post your valuable comments.
Get the latest vLemonn news first