Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
$9.99 | ALL EBOOKS & VIDEOS
Save more on purchases! Buy 2 and save 10%, Buy 3 and save 15%, Buy 5 and save 20%
Unreal Engine 4 Scripting with C++ Cookbook
Unreal Engine 4 Scripting with C++ Cookbook

Unreal Engine 4 Scripting with C++ Cookbook: Get the best out of your games by scripting them using UE4

By William Sherif , Stephen Whittle
$43.99 $9.99
Book Oct 2016 452 pages 1st Edition
eBook
$43.99 $9.99
Print
$54.99
Subscription
$15.99 Monthly
eBook
$43.99 $9.99
Print
$54.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now
Table of content icon View table of contents Preview book icon Preview Book

Unreal Engine 4 Scripting with C++ Cookbook

Chapter 1. UE4 Development Tools

In this chapter, we will outline basic recipes for getting started in UE4 game development, and the basic tools that we use for creating the code that makes your game. This will include the following recipes:

  • Installing Visual Studio

  • Creating and building your first C++ project in Visual Studio

  • Changing the code font and color in Visual Studio

  • Extension – changing the color theme in Visual Studio

  • Formatting your code (Autocomplete settings) in Visual Studio

  • Shortcut keys in Visual Studio

  • Extended mouse usage in Visual Studio

  • UE4 – installation

  • UE4 – first project

  • UE4 – creating your first level

  • UE4 – logging with UE_LOG

  • UE4 – making an FString from FStrings and other variables

  • Project management on GitHub – getting your Source Control

  • Project management on GitHub – using the Issue Tracker

  • Project management on VisualStudio.com – managing the tasks in your project

  • Project management on VisualStudio.com – constructing user stories and tasks

Introduction


Creating a game is an elaborate task that will require a combination of assets and code. To create assets and code, we'll need some pretty advanced tools including art tools, sound tools, level editing tools, and code editing tools. In this chapter, we'll discuss finding suitable tools for asset creation and coding. Assets include any visual artwork (2D sprites, 3D models), audio (music and sound effects), and game levels. Code is the text (usually C++) that instructs the computer on how to tie these assets together to make a game world and level, and how to make that game world "play." There are dozens of very good tools for each task; we will explore a couple of each, and make some recommendations. Game editing tools, especially, are hefty programs that require a powerful CPU and lots of memory, and very good, ideal GPUs for good performance.

Protecting your assets and work is also a necessary practice. We'll explore and describe source control, which is how you back up your work on a remote server. An introduction to Unreal Engine 4 Programming is also included, along with exploring basic logging functions and library use. Significant planning is also required to get the tasks done, so we'll use a task-planner software package to do so.

Installing Visual Studio


Visual Studio is an essential package for code editing when editing the C++ code for your UE4 game.

Getting ready

We're going to set up a C++ coding environment to build our UE4 applications. We'll download Visual Studio 2015, install it, and set it up for UE4 C++ coding.

How to do it...

  1. Begin by visiting https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx. Click on Download Community 2015. This downloads the ~200 KB loader/installer.

    Tip

    You can compare editions of Visual Studio at https://www.visualstudio.com/en-us/products/compare-visual-studio-2015-products-vs.aspx. The Community Edition of Visual Studio is fully adequate for UE4 development purposes in this book.

  2. Launch the installer, and select the components of Visual Studio 2015 that you want to add to your PC. Keep in mind that the more features you select, the larger your installation will be.

    The preceding screenshot shows a recommended minimum installation, with Common Tools for Visual C++ 2015, Git for Windows, and GitHub Extension for Visual Studio all checked. We will use the Git for Windows features in a later section in this chapter.

  3. After you have selected the tools you'd like to add onto Visual Studio, click the Next button. The installer tool will download the required components, and continue setup. Installation should take 20-40 minutes, depending on your option selections and connection speed.

  4. After you download and install Visual Studio 2015, launch it. You will be presented with a Sign in dialog box.

You can Sign in with your Microsoft account (the one you use to sign into Windows 10), or Sign up for a new account. After you've signed in or signed up, you will be able to sign into Visual Studio itself. It may seem odd to sign into a desktop code editing program, but your sign-in will be used for source control commits to your repositories. On first signing in to Visual Studio, you can select (one time only) a unique URL for your source code repositories as hosted on Visualstudio.com.

How it works...

Visual Studio is an excellent editor, and you will have a fantastic time coding within it. In the next recipe, we'll discuss how to create and compile your own code.

Creating and building your first C++ project in Visual Studio


In order to compile and run code from Visual Studio, it must be done from within a project.

Getting ready

In this recipe, we will identify how to create an actual executable running program from Visual Studio. We will do so by creating a project in Visual Studio to host, organize, and compile the code.

How to do it...

In Visual Studio, each group of code is contained within something called a Project. A Project is a buildable conglomerate of code and assets that produce either an executable (.exe runnable) or a library (.lib, or .dll). A group of Projects can be collected together into something called a Solution. Let's start by constructing a Visual Studio Solution and Project for a console application, followed by constructing a UE4 sample Project and Solution.

  1. Open Visual Studio, and go to File | New | Project...

  2. You will see a dialog as follows:

    Select Win32 in the pane on the left-hand side. In the right-hand pane, hit Win32 Console Application. Name your project in the lower box, then hit OK.

  3. In the next dialog box, we specify the properties of our console application. Read the first dialog box and simply click Next. Then, in the Application Settings dialog, choose the Console Application bullet, then under Additional options, choose Empty project. You can leave Security Development Lifecycle (SDL) checks unchecked.

  4. Once the application wizard completes, you will have created your first project. Both a Solution and a Project are created. To see these, you need Solution Explorer. To ensure that Solution Explorer is showing, go to View | Solution Explorer (or press Ctrl + Alt + L). Solution Explorer is a window that usually appears docked on the left-hand side or right-hand side of the main editor window as shown in the following screenshot:

    Solution Explorer also displays all the files that are part of the project. Using Solution Explorer, we will also add a code file into the editor. Right click on your Project FirstProject, and select Add | New Item…

  5. In the next dialog, simply select C++ File (.cpp), and give the file any name you'd like. I called mine Main.cpp.

  6. Once you have added the file, it will appear in Solution Explorer under your FirstProject's source file filter. As your Project grows, more and more files are going to be added to your project. You can compile and run your first C++ program using the following text:

    #include<stdio.h>
    
    int main()
    {
      puts("Welcome to Visual Studio 2015 Community Edition!");
    }
  7. Press Ctrl + Shift + B to build the project, then Ctrl + F5 to run the project.

  8. Your executable will be created, and you will see a small black window with the results of your program's run:

How it works...

Building an executable involves translating your C++ code from text language to a binary file. Running the file runs your game program, which is just the code text that occurs in the main() function between { and }.

There's more...

Build configurations are styles of build that we should discuss them here. There are at least two important build configurations you should know about: Debug and Release. The Build configuration selected is at the top of the editor, just below the toolbar in the default position.

Depending on which configuration you select, different compiler options are used. A Debug configuration typically includes extensive debug information in the build as well as turning off optimizations to speed up compilation. Release builds are often optimized (either for size or for speed), take a bit longer to build, and result in smaller or faster executables. Behavior stepping through with the debugger is often better in the Debug mode than the Release mode.

Changing the code font and color in Visual Studio


Customizing the font and color in Visual Studio is not only extremely flexible, you will also find it very necessary if your monitor resolution is quite high or quite low.

Getting ready

Visual Studio is a highly customizable code editing tool. You might find the default fonts too small for your screen. You may want to change your code's font size and color. Or you may want to completely customize the coloration of keywords and the text background colors. The Fonts and Colors dialog box, which we'll show you how to use in this section, allows you to completely customize every aspect of the code editor's font and color.

How to do it...

  1. From within Visual Studio, go to Tools | Options…

  2. Select Environment | Fonts and Colors from the dialog that appears. It will look like the following screenshot:

  3. Play around with the font and font size of Text Editor/Plain Text. Click OK on the dialog, and see the results in the code-text editor.

Text Editor/Plain Text describes the font and size used for all code text within the regular code editor. If you change the size of the font, the size changes for any text entered into the coding window (for all languages, including C, C++, C#, and others).

The color (foreground and background) is completely customizable for each item. Try this for the Text Editor/Keyword setting (affects all languages), or for C++-specific items, such as Text Editor/C++ Functions. Click OK, and you will see the changed color of the item reflected in the code editor.

You may also want to configure the font size of the Output Window—choose Show settings for => Output Window as seen in the following screenshot:

The Output Window is the little window at the bottom of the editor that displays build results and compiler errors.

Tip

You can't save-out (export) or bring in (import) your changes to the Fonts and Colors dialog. But you can use something called the Visual Studio Theme Editor Extension, learn more refer to Extension – changing the color theme in Visual Studio to export and import customized color themes.

For this reason, you may want to avoid changing font colors from this dialog. You must use this dialog to change the font and font-size, however, for any setting (at the time of writing).

How it works...

The Fonts and Colors dialog simply changes the appearance of code in the text editor as well as for other windows such as the output window. It is very useful for making your coding environment more comfortable.

There's more...

Once you have customized your settings, you'll find that you may want to save your customized Fonts and Colors settings for others to use, or to put into another installation of Visual Studio, which you have on another machine. Unfortunately, by default, you won't be able to save-out your customized Fonts and Colors settings. You will need something called the Visual Studio Theme Editor extension to do so. We will explore this in the next recipe.

See also

  • The Extension – changing the color theme in Visual Studio section describes how to import and export color themes

Extension – changing the color theme in Visual Studio


By default, you cannot save the changes you make to the font colors and background settings that you make in the Fonts and Colors dialog. To fix this issue, Visual Studio 2015 has a feature called Themes. If you go to Tools | Options | Environment | General, you can change the theme to one of the three pre-installed stock themes (Light, Blue, and Dark).

A different theme completely changes the look of Visual Studio—from the colors of the title bars to the background color of the text editor window.

You can also customize the theme of Visual Studio completely, but you'll need an extension to do so. Extensions are little programs that can be installed into Visual Studio to modify its behavior.

By default, your customized color settings cannot be saved or reloaded into another Visual Studio installation without the extension. With the extension, you will also be able to save your own color theme to share with others. You can also load the color settings made by another person or by yourself into a fresh copy of Visual Studio.

How to do it...

  1. Go to Tools | Extensions and Updates…

  2. From the dialog that appears, choose Online in the panel on the left-hand side. Start typing Theme Editor into the search box at the right. The Visual Studio 2015 Color Theme Editor dialog will pop up in your search results.

  3. Click the small Download button in the top right-hand corner of the entry. Click through the installation dialog prompts, allowing the plugin to install. After installation, Visual Studio will prompt you to restart.

    Tip

    Alternatively, visit https://visualstudiogallery.msdn.microsoft.com/6f4b51b6-5c6b-4a81-9cb5-f2daa560430b and download/install the extension by double-clicking the .vsix that comes from your browser.

  4. Click Restart Now to ensure the plugin is loaded.

  5. After restarting, go to Tools | Customize Colors to open the Color Themes editor page.

  6. From the Color Themes dialog that appears, click on the little palette-shaped icon on the upper-right corner of the theme that you want to use as your base or starting theme (I've clicked on the palette for the Light theme here, as you can see in the following screenshot).

  7. A copy of the theme will appear in the Custom Themes section in the lower part of the Color Themes window. Click on Edit Theme to modify the theme. When you are editing the theme, you can change everything from the font text color to the C++ keyword color.

  8. The main area you are interested in is the C++ Text Editor section. To gain access to all the C++ Text Editor options, be sure to select the Show All Elements option at the top of the Theme Editor window, as shown in the following screenshot:

    Note

    Be sure to select the Show All Elements option in the Theme Editor window to show C++-specific text editor settings. Otherwise, you'll be left with Chrome/GUI type modifications being possible only.

  9. Note that, while most of the settings you are interested in will be under Text Editor | C/C++, some will not have that C++ subheading. For example, the setting for the main/plain text inside the editor window (for all languages) is under Text Editor | Plain Text (without the C++ subheading).

  10. Select the theme to use from Tools | Options | Environment | General. Any new themes you have created will appear automatically in the drop-down menu.

How it works...

Once we load the plugin, it integrates into Visual Studio quite nicely. Exporting and uploading your themes to share with others is quite easy too.

Adding a theme to your Visual Studio installs it as an extension in Tools | Extensions and Updates…, To remove a theme, simply Uninstall its Extension.

Formatting your code (Autocomplete settings) in Visual Studio


Code-writing formatting with Visual Studio is a pleasure. In this recipe, we'll discuss how to control the way Visual Studio lays out the text of your code.

Getting ready

Code has to be formatted correctly. You and your co-programmers will be able to better understand, grok, and keep your code bug-free if it is consistently formatted. This is why Visual Studio includes a number of auto-formatting tools inside the editor.

How to do it...

  1. Go to Tools | Options | Text Editor | C/C++. This dialog displays a window that allows you to toggle Automatic brace completion.

    Automatic brace completion is the feature where, when you type { , a corresponding } is automatically typed for you. This feature may irk you if you don't like the text editor inserting characters for you unexpectedly.

    You generally want Auto list members on, as that displays a nice dialog with the complete names of data members listed for you as soon as you start typing. This makes it easy to remember variable names, so you don't have to memorize them:

    Tip

    If you press Ctrl + Spacebar inside the code editor at any time, the auto list pops up.

  2. Some more autocomplete behavior options are located under Text Editor | C/C++ | Formatting:

Autoformat section: Highlight a section of text and select Edit | Advanced | Format Selection (Ctrl + K, Ctrl + F).

How it works...

The default autocomplete and autoformat behaviors may irk you. You need to converse with your team on how you want your code formatted (spaces or tab indents, size of indent, and so on), and then configure your Visual Studio settings accordingly.

Shortcut keys in Visual Studio


Shortcut keys really save you time when coding. Knowing shortcut keys offhand is always good.

Getting ready

There are a number of shortcut keys that will make coding and project navigation much faster and more efficient for you. In this recipe, we describe how to use some of the common shortcut keys that will really enhance your coding speed.

How to do it...

The following are some very useful keyboard shortcuts for you to try:

  1. Click on one page of the code, then click somewhere else, at least 10 lines of code away. Now press Ctrl + - [navigate backwards]. Navigation through different pages of source code (the last place you were at, and the place you are at now) is done by pressing Ctrl + - and Ctrl + Shift + - respectively.

    Tip

    Warping around in the text editor using Ctrl + -. The cursor will jump back to the last location it was in that is more than 10 lines of code away, even if the last location was in a separate file.

    Say, for example, you're editing code in one place, and you want to go back to the place you've just been (or go back to the section in the code you came from). Simply press Ctrl + -, and that will warp you back to the location in the code you were at last. To warp forward to the location you were at before you pressed Ctrl + -, press Ctrl + Shift + -. To warp back, the previous location should be more than 10 lines away, or in a different file. These correspond to the Forward and Back menu buttons in the toolbar:

    Tip

    The Back and Forward navigation buttons in the toolbar, which correspond to the Ctrl + - and Ctrl + Shift + - shortcuts respectively.

  2. Press Ctrl + W to highlight a single word.

  3. Press and hold Ctrl + Shift + right arrow (or left arrow) (not Shift + right arrow) just to move to the right and left of the cursor, selecting entire words.

  4. Press Ctrl + C to copy text, Ctrl + X to cut text, and Ctrl + V to paste text.

  5. Clipboard ring: The clipboard ring is a kind of a reference to the fact that Visual Studio maintains a stack of the last copy operations. By pressing Ctrl + C, you push the text that you are copying into an effective stack. Pressing Ctrl + C a second time on different text pushes that text into the Clipboard Stack. For example, in the following diagram, we pressed Ctrl + C on the word cyclic first, then Ctrl + C on the word paste afterwards.

    As you know, pressing Ctrl + V pastes the top item in the stack. Pressing Ctrl + Shift + V accesses a very long history of all the items ever copied in that session, that is, items underneath the top item in the stack. After you exhaust the list of items, the list wraps back to the top item in the stack. This is an odd feature, but you may find it useful occasionally.

  6. Ctrl + M, Ctrl + M collapses a code section.

How it works...

Keyboard shortcuts allow you to speed up work in the code editor by reducing the number of mouse reaches that you have to perform in a coding session.

Extended mouse usage in Visual Studio


The mouse is a pretty handy tool for selecting text. In this section, we'll highlight how to use the mouse in an advanced way for quick edits to your code's text.

How to do it...

  1. Hold down the Ctrl key while clicking to select an entire word.

  2. Hold down the Alt key to select a box of text (Alt + Left Click + Drag).

You can then either cut, copy, or overwrite the box-shaped text area.

How it works...

Mouse clicking alone can be tedious, but with the help of Ctrl + Alt, it becomes quite cool. Try Alt + Left Click + Drag for selecting a row of text, then typing as well. The characters you type will be repeated in rows.

UE4 – installation


There are a number of steps to follow to install and configure UE4 properly. In this recipe, we'll walk through the correct installation and setup of the engine.

Getting ready

UE4 takes up quite a few GB of space, so you should have at least 20 GB or so free for the installation on the target drive.

How to do it...

  1. Visit unrealengine.com and download it. Sign up for an account if required.

  2. Run the installer for the Epic Games Launcher Program by double-clicking the EpicGamesLauncherInstaller-x.x.x-xxx.msi installer. Install it in the default location.

  3. Once the Epic Games Launcher program is installed, open it by double-clicking its icon on your desktop or in the Start menu.

  4. Browse the start page and take a look around. Eventually, you will need to install an engine. Click on the large orange Install Engine button on the top-left side from the UE4 tab, as shown in the following image:

  5. A pop-up dialog will show the components that can be installed. Select the components you'd like to install. The recommendation is to begin by installing the first three components (Core Components, Starter Content, and Templates and Feature Packs). You can leave out the Editor symbols for debugging component if you will not be using it.

  6. After the engine has installed, the Install Engine button will change to a Launch Engine button.

How it works...

The Epic Games Launcher is the program that you need to start up the engine itself. It keeps a copy of all your projects and libraries in the Library tab.

There's more...

Try downloading some of the free library packages in the Library | Vault section. For that, click the Library item on the left side, and scroll down until you see Vault, underneath My Projects.

UE4 – first project


Setting up a Project within UE4 takes a number of steps. It is important to get your options correct so that you can have the setup that you like, so carefully follow this recipe when constructing your first project.

Each project that you create within UE4 takes up at least 1 GB of space or so, so you should decide whether you want your created projects on the same target drive, or on an external or separate HDD.

How to do it...

  1. From the Epic Games Launcher, click on the Launch Unreal Engine 4.11.2 button. Once you are inside the engine, an option to create a new project or load an existing one will presents itself.

  2. Select the New Project tab.

  3. Decide whether you will be using C++ to code your project, or Blueprints exclusively.

    1. If using Blueprints exclusively, make your selection of a template to use from the Blueprint tab.

    2. If using C++ in addition to Blueprints to construct your project, select the project template to construct your project based on the C++ tab.

    3. If you're not sure what template to base your code on, BASIC Code is an excellent starting point for any C++ project (or Blank for a Blueprint-exclusive project).

  4. Take a look at the three icons that appear beneath the template listing. There are three options here to configure:

    1. You can choose to target Desktop or Mobile applications.

    2. You have an option to alter the quality settings (the picture of a plant with magic). But you probably don't need to alter these. The quality settings are reconfigurable under Engine | Engine Scalability Settings anyway.

    3. The last option is whether to include Starter Content with the project or not. You can probably use the Starter Content package in your project. It has some excellent materials and textures available within it.

    Tip

    If you don't like the Starter Content package, try the packages in the UE4 Marketplace. There is some excellent free content there, including the GameTextures Material Pack.

  5. Select the drive and folder in which you will save your project. Keep in mind that each project is roughly 1 GB in size, and you will need at least that much space on the destination drive.

  6. Name your project. Preferably name it something unique and specific to what you are planning on creating.

  7. Hit Create. Both the UE4 Editor and Visual Studio 2015 windows should pop up, enabling you to edit your project.

    Tip

    In the future, keep in mind that you can open the Visual Studio 2015 Solution via one of the two following methods:

    • Via your local file explorer. Navigate to the root of where your project is stored, and double-click on the ProjectName.sln file.

    • From UE4, click on File | Open Visual Studio.

UE4 – creating your first level


Creating levels in UE4 is easy and facilitated by a great UI all around. In this recipe, we'll outline basic editor use and describe how to construct your first level once you have your first project launched.

Getting ready

Complete the previous recipe, UE4 – First Project. Once you have a project constructed, we can proceed with creating a level.

How to do it…

  1. The default level that gets set up when you start a new project will contain some default geometry and scenery. You don't need to start with this starter stuff, however. If you don't want to build from it, you can delete it, or create a new level.

  2. To create a new level, click File | New Level… and select to create a level with a background sky (Default), or without a background sky (Empty Level).

    Tip

    If you choose to create a level without a background sky, keep in mind that you must add a light to it to see the geometry you add to it effectively.

  3. If you loaded the Starter Content on your project's creation (or some other content), then you can use the Content Browser to pull content into your level. Simply drag and drop instances of your content from the Content Browser into the level, save, and launch them.

  4. Add some geometry to your level using the Modes panel (Window | Modes). Be sure to click on the picture of a light bulb and cube to access the placeable geometry. You can also add lights via the Modes tab by clicking on the Lights subtab on the left-hand side of the Modes tab.

Note

The Modes panel contains two useful items for level construction: some sample geometry to add (cubes and spheres and the like) as well as a panel full of lights. Try these out and experiment to begin laying out your level.

UE4 – logging with UE_LOG


Logging is extremely important for outputting internal game data. Using log tools lets you print information into a handy little Output Log window in the UE4 editor.

Getting ready

When coding, we may sometimes want to send some debug information out to the UE log window. This is possible using the UE_LOG macro. Log messages are an extremely important and convenient way to keep track of information in your program as you are developing it.

How to do it...

  1. In your code, enter a line of code using the form:

    UE_LOG(LogTemp, Warning, TEXT("Some warning message") );
    
  2. Turn on the Output Log inside the UE4 editor to see your log messages printed in that window as your program is running.

How it works...

The UE_LOG macro accepts a minimum of three parameters:

  • The Log category (we used LogTemp here to denote a log message in a temporary log)

  • The Log level (we used a warning here to denote a log message printed in yellow warning text)

  • A string for the actual text of the log message itself

Do not forget the TEXT() macro around your log message text! It promotes the enclosed text to Unicode (it prepends an L) when the compiler is set to run with Unicode on.

UE_LOG also accepts a variable number of arguments, just like printf() from the C programming language.

int intVar = 5;
float floatVar = 3.7f;
FString fstringVar = "an fstring variable";
UE_LOG(LogTemp, Warning, TEXT("Text, %d %f %s"), intVar, floatVar, *fstringVar );

There will be an asterisk * just before FString variables when using UE_LOG to dereference the FString to a regular C-style TCHAR pointer.

Tip

TCHAR is usually defined as a variable type where, if Unicode is being used in the compile, the TCHAR resolves to wchar_t. If Unicode is off (compiler switch _UNICODE not defined), then TCHAR resolves to simply char.

Don't forget to clear your log messages after you no longer need them from the source!

UE4 – making an FString from FStrings and other variables


When coding in UE4, you often want to construct a string from variables. This is pretty easy using the FString::Printf or FString::Format functions.

Getting ready

For this, you should have an existing project into which you can enter some UE4 C++ code. Putting variables into a string is possible via printing. It may be counterintuitive to print into a string, but you can't just concatenate variables together, and hope that they will automatically convert to string, as in some languages such as JavaScript.

How to do it…

  1. Using FString::Printf():

    1. Consider the variables you'd like printed into your string.

    2. Open and take a look at a reference page of the printf format specifiers, such as http://en.cppreference.com/w/cpp/io/c/fprintf.

    3. Try code such as the following:

      FString name = "Tim";
      int32 mana = 450;
      FString string = FString::Printf( TEXT( "Name = %s Mana = %d" ), *name, mana );

    Notice how the preceding code block uses the format specifiers precisely as the traditional printf function does. In the preceding example, we used %s to place a string in the formatted string, and %d to place an integer in the formatted string. Different format specifiers exist for different types of variables, and you should look them up on a site such as cppreference.com.

  2. Using FString::Format(). Write code in the following form:

    FString name = "Tim";
    int32 mana = 450;
    TArray< FStringFormatArg > args;
    args.Add( FStringFormatArg( name ) );
    args.Add( FStringFormatArg( mana ) );
    FString string = FString::Format( TEXT( "Name = {0} Mana = {1}" ), args );
    UE_LOG( LogTemp, Warning, TEXT( "Your string: %s" ), *string );

    With FString::Format(), instead of using correct format specifiers, we use simple integers and a TArray of FStringFormatArg instead. The FstringFormatArg helps FString::Format() deduce the type of variable to put in the string.

Project management on GitHub – getting your Source Control


A very important thing to do for your project as you're developing it is to generate a timeline history as you're working. To do so, you need to back up your source code periodically. A great tool for doing so is Git. Git allows you to park changes (commits) into a repository online on a remote server so that your code's development history is documented and preserved on that remote server. If your local copy gets damaged somehow, you can always recover from the online backups. This timeline-history of your codebase's development is called Source Control.

Getting ready

There are a couple of free services that offer online source backups. Some of the free alternatives for storing your data include:

  • Visualstudio.com: limited/private sharing of your repository

  • github.com: unlimited public sharing of your repositories

Visualstudio.com is great for when you want some privacy for your project for free, while GitHub is great when you want to share your project with lots of users for free. Visualstudio.com also offers some very good workboarding and planning features, which we will use later in this text (GitHub also offers a competing Issue Tracker, which we'll discuss later on as well).

The website you choose depends mostly on how you plan on sharing your code. In this text, we will use GitHub for source code storage, since we need to share our code with a large number of users (you!)

How to do it...

  1. Sign up for a GitHub account at https://github.com. Sign into your GitHub account using the Team Explorer menu (View | Team Explorer).

  2. Once you have the Team Explorer open, you can sign into your GitHub account using the button that appears in the Team Explorer window.

  3. After you've signed in, you should gain the capability to Clone and Create repositories. These options will appear right underneath the GitHub menu in the Team Explorer.

  4. From here, we want to create our first repository. Hit the Create button, and name your repository in the window that comes up.

    Tip

    When creating your project, take care to select the VisualStudio option from the .gitignore options menu. This will cause Git to ignore the Visual Studio-specific files that you don't want included in your repository, such as the Build and Release directories.

  5. Now you have a repository! The repository is initialized on GitHub. We just have to put some code into it.

  6. Open up the Epic Games Launcher, and create a project to put into the repository.

  7. Open the C++ project in Visual Studio 2015, and right-click on Solution. Select Add Solution to Source Control from the context menu that appears. The dialog that appears will ask whether you want to use Git or TFVC.

    Tip

    If you use Git for your source control, then you can host on either github.com or Visualstudio.com.

  8. After you add Git Source Control to the project, take a look at Team Explorer again. From that window, you should enter a brief message, then click on the Commit button.

How it works...

Git repositories are important for backing up copies of your code and project files as your project evolves. There are many commands within Git to browse the project history (try the Git GUI tool), see what changes you've made since the last commit (git diff), or move backward and forward through the Git history (git checkout commit-hash-id).

Project management on GitHub – using the Issue Tracker


Keeping track of you project's progress, features, and bugs is extremely important. The GitHub Issue Tracker will enable you to do this.

Getting ready

Keeping track of your project's planned features and running issues is important. GitHub's Issue Tracker can be used to create lists of features you'd like to add to your project as well as bugs you need to fix at some time in the future.

How to do it...

  1. To add an issue to your Issue Tracker, first select the repository that you'd like to edit by going to the front page of GitHub and selecting the Repositories tab:

  2. From your repository's homepage, select the Issues tab under your repository. To add an issue to track, click the New Issue button in the lower-right corner of the screen, as seen in the following screenshot:

  3. When adding your issue, it is good practice to detail it as much as possible. Including screenshots and diagrams in the features or bugs you post is highly recommended, as it documents the issue much better, and parks important information and a good description into your Issue Tracker. Dragging and dropping images into the text editor window automatically uploads a copy of the image to GitHub's own cloud server, and the image will appear inline in the issue, as shown in the following screenshot:

  4. The box into which you enter the description of your bug or feature supports Markdown. Markdown is a simplified HTML-like markup language that lets you quickly write HTML-like syntax with ease. Examples of some markdown syntax are as follows:

    # headings
    ## sub-headings
    ### sub-sub-headings
    _italics_, __bold__, ___bold-italics___
    [hyperlinks](http://towebsites.com/)
    
    code (indented by 4 spaces), preceded by a blank line
    
    * bulleted
    * lists
      - sub bullets
        - sub sub bullets
    
    >quotations

    Tip

    If you want to learn more about Markdown's syntax, check out https://daringfireball.net/projects/markdown/syntax.

  5. You can further mark the issue as either a bug, enhancement (feature), or any other label you like. Customizing labels is possible via the Issues | Labels link:

  6. From there, you can edit, change the color of, or delete your labels. I deleted all the stock labels, and replaced the word enhancement with feature, as seen in the following two screenshots:

  7. Once you've fully customized your labels, your GitHub Issue Tracker is much easier to navigate. Prioritize issues by tagging with the appropriate labels.

How it works...

GitHub's Issue Tracker is a fantastic way to track bugs and features in your project. Using it not only organizes your workflow, but also maintains an excellent history of the work done on the project.

See also

  • You should also check out the Wiki feature, which allows you to document your source code

Project management on VisualStudio.com – managing the tasks in your project


High-level management of your project is usually done using a planning tool. GitHub's Issue Tracker may meet your needs, but if you're looking for more, Microsoft's Visual Studio Team Services offers planning tools for Scrum and Kanban style programming assignment of tasks (Features, Bugs, and so on).

Using this tool is a great way to organize your tasks to make sure things get done on time, and to get used to an industrial-standard workflow. When you sign up for Visual Studio's Community Edition during setup, your account includes free use of these tools.

How to do it...

In this section, we'll describe how to use the Workboard feature on Visualstudio.com to plan a few simple tasks.

  1. To create your own project Workboard, go to your account at Visualstudio.com. Log in, and then select the Overview tab. Under Recent projects & teams title, select the New link.

  2. Add a Project name and Description to your project. After you've named your project (I've named mine Workboards), click on Create project. You will wait a second or two for project creation to complete, then hit the Navigate to project button in the next dialog.

  3. The next screen that is shown allows you to navigate to the Workboards area. Click on Manage Work.

  4. The Manage Work screen is a Kanban styled (read: prioritized) task queue of things to do in your project. You can hit the New item button to add new items to your list of things to do.

Tip

As soon as you add something to your to-do list, it is called being part of your backlog. In Kanban, you're always behind! If you're a manager, you never want an empty backlog.

How it works…

Each item on your Board's backlog is called a User Story. A User Story is an Agile software development term, and each User Story is supposed to describe a need of a particular end user. For example, in the preceding User Story, the need is to have visual graphics, and the User Story describes that graphics (sprites) must be created to satisfy this user requirement.

User stories will often have a specific format:

Note

As a <someone>, I want <this> so that <advantage>.

For example:

Note

As a <player of the game> I want to <reorganize items> so that I can <set hotkeys to slots that I desire>.

On the Workboard, you'll have a bunch of user stories. I have placed a few user stories earlier so we can play with them.

Once your board is filled with user stories, they will all sit in the New vertical column. As you start work on or make progress on a particular User Story, you can drag it horizontally from New to Active, then finally to Resolved and Closed when the User Story is complete.

Project management on VisualStudio.com – constructing user stories and tasks


From the Scrum point of view, a User Story is grouping of tasks that need to be done. A group of user stories can be collected into a Feature, and a group of Features can be gathered together into what is called an Epic . VisualStudio.com organizes User Story creation very well so that it's easy to construct and plan the completion of any particular task (user story). In this recipe, we'll describe how to assemble and put together user stories.

Getting ready

Every item entered into VisualStudio.com's project management suite should always be a feature that somebody wants to be in the software. User story creation is a fun, easy, and exciting way to group together and mete out bunches of tasks to your programmers as work to be done. Log in to your VisualStudio.com account now, edit one of your projects, and begin using this feature.

How to do it…

  1. From the VisualStudio.com Team Services landing page, navigate to the project into which you want to enter some new work to be done. All of your Projects can be found if you click on Browse under the Recent projects & teams heading.

  2. Select the project that you want to work with and hit Navigate.

  3. Tasks inside Visualstudio.com take place inside of one of the three categories of super task:

    • User Story

    • Features

    • Epics

      Tip

      User Stories, Features, and Epics are just organizational units for work. An Epic contains many Features. A Feature contains many User Stories, and a User Story contains many Tasks.

      By default, Epics are not shown. You can display Epics by going to Settings (the gear icon on the right side of the screen). Then navigate to General | Backlogs. Under the section that says See only the backlogs your team manages, select to display all three flavors of Backlog: Epics, Features, and Stories.

  4. There are now four navigation steps to perform before you can enter your first task (User Story) into the Backlog:

    1. From the menu bar at the top, select WORK.

    2. Then, in the submenu that appears on the WORK page, select Backlogs.

    3. On the sidebar that appears, click on Stories.

    4. From the panel on the right-hand side, select Board.

      Tip

      Backlog is the set of User Stories and Tasks that we have yet to complete. You might think, "Are brand new tasks really entered into a Backlog?" That's right! You're already behind! The implications of Scrum's terminology seem to imply "overflowing with work".

  5. From the panel on the right-hand side, hit New item, and fill in the text for your new User Story item.

  6. Click on the text of the User Story card, and fill in the fields for Assignee, the Iteration that it's a part of, Description, tags, and any other fields of the Details tab that you want to explore.

  7. Next we break down the overall User Story into a series of achievable tasks. Hover over your new User Story item until the ellipsis (three dots…) appears. Click on the ellipsis, and select + Add Task.

  8. List the details of completing the User Story in the series of Tasks.

  9. Assign each Task to:

    • An Assignee

    • An Iteration

      Tip

      Simply put, an Iteration is really just a time period. At the end of each iteration, you should have a deliverable, testable piece of software completed. Iteration is a time period that refers to producing yet another version of your amazing software (for testing and possible release).

  10. Continue adding Tasks to the project as the project develops features to complete and bugs to fix.

How it works…

Epics contain a number of Features. Features contain a number of User Stories, and User Stories contain a number of Tasks and Tests.

All of these items are assignable to a User (an actual human), and to an Iteration (time period), for both assigning responsibility and scheduling a task. Once these are assigned, the task should appear in the Queries tab.

Tip

Detailed steps to download the code bundle are mentioned in the Preface of this book. Please have a look.

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Unreal-Engine-4-Scripting-with-CPlusPlus-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Left arrow icon Right arrow icon

Key benefits

  • A straightforward and easy-to-follow format
  • A selection of the most important tasks and problems
  • Carefully organized instructions to solve problems efficiently
  • Clear explanations of what you did
  • Solutions that can be applied to solve real-world problems

Description

Unreal Engine 4 (UE4) is a complete suite of game development tools made by game developers, for game developers. With more than 100 practical recipes, this book is a guide showcasing techniques to use the power of C++ scripting while developing games with UE4. It will start with adding and editing C++ classes from within the Unreal Editor. It will delve into one of Unreal's primary strengths, the ability for designers to customize programmer-developed actors and components. It will help you understand the benefits of when and how to use C++ as the scripting tool. With a blend of task-oriented recipes, this book will provide actionable information about scripting games with UE4, and manipulating the game and the development environment using C++. Towards the end of the book, you will be empowered to become a top-notch developer with Unreal Engine 4 using C++ as the scripting language.

What you will learn

[*] Build function libraries (Blueprints) containing reusable code to reduce upkeep [*] Move low-level functions from Blueprint into C++ to improve performance [*] Abstract away complex implementation details to simplify designer workflows [*] Incorporate existing libraries into your game to add extra functionality such as hardware integration [*] Implement AI tasks and behaviors in Blueprints and C++ [*] Generate data to control the appearance and content of UI elements

Product Details

Country selected

Publication date : Oct 24, 2016
Length 452 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781785885549
Vendor :
Unity Technologies
Category :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Oct 24, 2016
Length 452 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781785885549
Vendor :
Unity Technologies
Category :
Concepts :

Table of Contents

19 Chapters
Unreal Engine 4 Scripting with C++ Cookbook Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Authors Chevron down icon Chevron up icon
About the Reviewer Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. UE4 Development Tools Chevron down icon Chevron up icon
2. Creating Classes Chevron down icon Chevron up icon
3. Memory Management and Smart Pointers Chevron down icon Chevron up icon
4. Actors and Components Chevron down icon Chevron up icon
5. Handling Events and Delegates Chevron down icon Chevron up icon
6. Input and Collision Chevron down icon Chevron up icon
7. Communication between Classes and Interfaces Chevron down icon Chevron up icon
8. Integrating C++ and the Unreal Editor Chevron down icon Chevron up icon
9. User Interfaces – UI and UMG Chevron down icon Chevron up icon
10. AI for Controlling NPCs Chevron down icon Chevron up icon
11. Custom Materials and Shaders Chevron down icon Chevron up icon
12. Working with UE4 APIs Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.