Updates to Unreal Course – Unreal Engine 4

Learn Unreal and C++ as part of our epic bundle Build 177 Games: The Complete 2D, 3D and VR Bundle

1. Receiving errors about Box Component?

Add the line below to the top of the cpp file that is producing errors. #include "Components/BoxComponent.h"

This line creates a reference to access components in the BoxComponent.h script. (Unreal Engine 4.15 requires separate includes.)

2. To get UGameplayStatics to compile you need to add:

#include "Kismet/GameplayStatics.h"

3. I’m getting errors in Visual Studio. What do they mean?

Many times you can ignore Visual Studio’s error messages.

If your project builds successfully in Unreal, you are good to go.

Visual Studio can mark things in the source code as an error even though it’s not.

This occurs because when generating new source files, Unreal can get out of sync with Visual Studio.

To sync Visual Studio with Unreal, go File -> Refresh Visual Studio Project.

Thanks to Mammoth Interactive students James and Chris for helping with this question!

Learn Unreal and C++ as part of our epic bundle Build 177 Games: The Complete 2D, 3D and VR Bundle

Creating a C++ Script | Unreal Tutorial

Scripts are so important when it comes to making a game in Unreal. For an in-depth lesson on Unreal, consider enrolling in Mammoth Interactive’s Unreal course

If you want to add a player to your game, you need to write code to give the player its own behavior. Default modes contain logic from Unreal. To create a new mode with custom behavior, you need to write a script.

Go to C++ Classes > CoinCollector in the Content Browser. Right-click in the Content Browser. Select “New C++ Class”.

Select “Pawn” from the “Choose Parent Class” to extend a pawn. With the Pawn class, the mode to be able to receive input from the player. The player will be able to move the mode.

Press Next. Name the pawn “HeroController”. Our player to be a hero who collects coins. Press “Create Class”. Unreal will create the script. Note that it does take some time for Unreal to create or compile a script.

We will enable HeroController to move based on user input. When the code compiles, you can open Xcode to view the files of the script if you are on a Mac. If you do not own Xcode, you can download it from the App Store. Xcode is a free program that you can use to write code.

If you are using Windows, you can use Visual Studio to write your code. Visual Studio should already be on your computer.

The Files of a C++ Script

Two files will open with the script: HeroController.h and HeroController.cpp. These are two different files for a single class. .h files are header files. They are used to list variables and methods in a class.

.cpp files are implementation files. They are used to implement those methods and variables. HeroController.cpp contains the implementation of HeroController’s behavior.

We will begin coding in HeroController.h. Some default code is already in the file. class COINCOLLECTOR_API AHeroController : public creates the class. Then there are five public functions:

  • The ACoinController function is a constructor. ACoinController is called when the script loads (when the object is created).
  • BeginPlay is a function that is called when the game starts (after the constructor and internal processes complete). A function performs a method or operation. You can use functions to set the behavior of an object.
  • Tick is a function that is called every frame (every time the game is processed by your computer, smartphone, or console).
  • SetupPlayerInputComponent is a function that is called to configure the input. Whenever we want to make HeroController move left, right, top, or bottom, we need to register the input bindings in this function.

Note that typing // in front of a line turns the code into a comment, which is not read by the compiler. You can use comments to organize code.

To learn how to build 6 games in Unreal, enroll in our Unreal course.