Unreal Engine 4 Tutorial
Unreal Engine 4 Tutorial
These are the slides that accompany the Complete Unreal Developer Course.
● Right click or Insert > Comment to comment, especially if you see a typo
● A PDF version will be attached inside the Unreal course.
● The slides will update immediately as I change things.
Ben Tristem
View and comment online at http://bit.ly/UnrealSlides
In This Video...
● Welcome to the first actual coding video.
● Why we’re doing this in the IDE only.
● What you’ll be building, see resources.
● You’ll learn types, loops, routines, classes.
● We’ll follow Unreal’s coding style, and re-use.
● Notes and resources are attached.
In This Video...
● How much planning should we do?
● Define the emotional problem the game solves*
● Chose concept, rules & requirements.
● Start to think about the architecture.
● Copy as much as possible into the code!
● Document now what may change later.
* McConnell, Steve. Code Complete. Microsoft Press 2004. Chapter 3.3
The Problem
● I want a mental challenge.
● I want to feel smart / prove myself.
● I miss word puzzles.
● I want to prove myself.
● I want to challenge (feel superior to) someone!
● Etc
Requirements
● Plain text instructions for all interactions.
● Code to help the player make a valid guess (e.g. all
lowercase, an isogram, right length).
● Code to check the number of Bulls and Cows in
the guess, compared the hidden word.
● Code to keep track of the number of valid
guesses.
In This Video...
● How projects and solutions relate.
● Setting up a new command line project.
● An overview of the structure of our solution.
● (Adding main.cpp to our project).
PROJECT 1 PROJECT 2
In This Video...
● The difference between an engine and a library.
● How this relates to this console application.
● What is building / compiling code?
● How the console knows where to find our code.
● The syntax of a function in C++.
● Write the minimal C++ program to remove error.
● Testing our application runs without error.
http://stackoverflow.com/questions/2872543/printf-vs-cout-in-c
In This Video...
● What a “magic number” is.
● Why it’s a good idea to avoid them.
● constexpr means “evaluated at compile time”.
● Introduce coding standards*.
● Use a constant for the word length.
*https://docs.unrealengine.
com/latest/INT/Programming/Development/CodingStandard/index.html
In This Video...
● The difference between \n and endl
● Introducing pseudocode programming
● Why we need to #import <string>
● Getting input using cin
● Discovering woes with our input buffer.
In This Video...
● Re-cap the problem we have.
● Why getline() is useful here.
● Where to find C++ documentation.
● A word on non-obvious solutions.
In This Video...
● Programming is all about managing complexity.
● We want to think about a few things at a time.
● The idea of abstraction and encapsulation.
● How functions help us simplify.
● Write and call your first functions.
● A warning about “side-effects” of functions.
● Always use return at the end of your functions.
In This Video...
● Why we need loops.
● When to use for vs while.
● The syntax of a for loop.
● Think carefully about the first & last loop.
● Write a for loop to repeat the game.
http://www.cplusplus.com/doc/tutorial/control
https://msdn.microsoft.com/en-us/library/b80153d8.aspx
In This Video...
● More about levels of abstraction.
● A word on being clever.
● Using Visual Studio’s Extract “Extract Function”
● What a header file (.h) is.
● What’s refactoring, and why we do it.
● Removing side-effects.
● Where to find the course code on GitHub.
An aviation quote...
In This Video...
● What a boolean is, and how to use it.
● Only use when completely clear what you mean.
● Use == for comparison.
● Use && for logical AND.
● Use || for logical OR.
● Use [n] to access a string, starting at n=0.
● Use ‘ ‘ for characters, and “ “ for strings.
In This Video...
● What a do while loop is.
● How it executes code one or more times.
● Making our game play multiple times.
http://www.cplusplus.com/doc/tutorial/control
https://msdn.microsoft.com/en-us/library/b0kk5few.aspx
View and comment online at http://bit.ly/UnrealSlides
Introducing Classes
@UnrealCourse :: www.UnrealCourse.com
In This Video...
● Lookup the Turing machine.
● A quick overview of the MVC pattern.
● User defined types (classes).
● About working at an interface level (black box).
● An overview of class FBullCowGame
Implement GetCurrentTry()
● Initialise the value to 1 in the header file (for now)
● Check it works by printing the try from GetGuess()
● For example: “Try 1. Enter your guess: “
● where 1 is the value of MyCurrentTry.
Pseudocode Programming
@UnrealCourse :: www.UnrealCourse.com
In This Video...
● More on Pseudocode Programming Practice (PPP)
● Reviewing our code and architecture
● Using // TODO as a comment prefix
● Introducing Visual Studio’s Task List
● Planning our next wave of coding.
if syntax
if (condition1) {
statements;
} else if (condition2) {
statements;
} else {
statements;
}
In This Video...
● A very brief intro to Visual Studio’s debugger
● Set a break-point by clicking in margin
● Watch values by highlighting in debug mode
● Use “Continue” to cycle back to breakpoint.
In This Video...
● Centralising the hidden word length
● Making this a property of the game class
● Writing a getter to access this value
● Updating our intro to vary with word length.
Introducing enumerations
@UnrealCourse :: www.UnrealCourse.com
In This Video...
● An enumerated type consists of named values
● Use instead of coded meaning
● Makes the code more readable and meaningful
● Only defined values can be used - more robust
● A benefit of C++ 11’s strongly typed enums
● Creating an enum class for error checking.
In This Video...
● Use else if for the first time
● Outline or CheckGuessValidity() method
● Write working code for checking guess length
● Use the debugger to test the return values.
In This Video...
● Use our error values to communicate with user
● All our user interaction is via GameManager.cpp
● We’ll use FText in this file, as it’s UI text
● We can “switch” what we say based on the error
● The syntax of a switch statement
● Remember your break keywords!
Finish IsGameWon()
● Define the appropriate getter method
● Create a private variable, prefixed with b
● Set the private variable in SubmitValidGuess()
● Test you can now win the game.
Define PrintGameSummary()
● Arrange for a “You won / bad luck” message
● Decide where in the program it goes
● Write a function for it
● Test it works.
Further reading
● http://stackoverflow.com/questions/9107516/sorting-characters-of-a-c-
string
● http://en.cppreference.com/w/cpp/algorithm/sort
● http://www.wolframalpha.com/input/?i=n%5E2+vs+%28n+log+n%
29+vs+n%2C+n%3D2+to+17
● https://en.wikipedia.org/wiki/Sorting_algorithm
● https://en.wikipedia.org/wiki/Big_O_notation
● https://en.wikipedia.org/wiki/Isogram
In This Video...
● The importance of knowing your data types
● Introducing the std::map data type
● #define TMap std::map to keep it ‘Unreal’
● How we’ll be using the map
● Wiring-up and pseudocoding IsIsogram().
h true
p true
Pseudocode IsIsogram()
● Only write comments for now
● Indent the comments as necessary
● Avoid code in the comments, work at a high level
● Run through mentally with some examples.
std::map syntax
● TMap<char, bool> LetterSeen; to declare
● Using LetterSeen[Letter] to access
● You can assign to the map element
● e.g. LetterSeen[Letter] = true;
Finish IsIsogram()
● Finish the function
● Test it thoroughly
● Try entering just \0 as a guess
● Try a blank string
● Try mixed case e.g. Aa
● Share your implementation in the discussions.
Design a Helper Function
@UnrealCourse :: www.UnrealCourse.com
In This Video...
● Gain confidence with a multi-stage challenge
● A word on implicit dependencies.
In This Video...
● Having someone else play test your game is vital
● Silently take notes, or record screen if possible
● Immediately go away and fix obvious bugs
● For improvements consider 2nd or 3rd opinion
● Repeat until the bug / issue rate plateaus.
In This Video...
● HUGE congratulations on your progress
● Over 6 hours of pure C++ learning
● Over 30 challenges you’ve completed
● The journey has only just begun
● Share your source code for others to play
● Here are some suggested improvements
● Next we take the game logic into Unreal :-)
Suggested improvements
● Easy, medium, hard which changes max tries
● Explain what an isogram is in the text*
● Define bulls and cows to the user*
● Explain the rules of the game more fully*
Class or Struct
Property or Field
Method or Function
Namespace
1. https://msdn.microsoft.com/en-us/library/y47ychfe.aspx
2. http://stackoverflow.com/questions/6662395/xcode-intellisense-meaning-of-letters-in-colored-
boxes-like-f-t-c-m-p-c-k-etc
http://www.cprogramming.com/tutorial/c++-iostreams.html
http://www.cprogramming.com/tutorial/c++-iostreams.html
http://stackoverflow.com/questions/156767/whats-the-difference-between-an-
argument-and-a-parameter
*https://docs.unrealengine.
com/latest/INT/Programming/Development/CodingStandard/index.html