Building and RPG With Unreal 4.X (book)

Dear community, this book is a little outdated, and will continue to be as well. I created this page to gather all fixes to the code and examples of this book while I'm following its examples in ve...

Updated over 4 years ago Edit Page Revisions

Dear community, this book is a little outdated, and will continue to be as well. I created this page to gather all fixes to the code and examples of this book while I'm following its examples in version 4.18.2 so that the rest of the people can find and add more items here.

Chapter 1

Chapter 2

  • Page 19: File | Add Code To Project is File | New C++ Class

  • Page 22: Graph tab is now Events Graph, where the Event Begin Play is already loaded.

  • Page 25: You can also drop the variable to the graph to select Get or Set

  • Page 28

  • It won't work without #include "Engine/DataTable.h" before the #include "TestCustomData.generated.h" line In 4.11+, GENERATED_BODY() should be used instead of GENERATED_USTRUCT_BODY()

  • Page 29: If you use microsoft excel, you will get a file with ";" instead of commas. Edit the file by hand and change commas and remove the , from the text fields too, so that it doesn't conflict.

  • Page 30:

  • #include TestCustomData.h --> #include "TestCustomData.h" The include should go in the header file before the generated.h include, or if we want to put it in the .cpp file, then a class predeclaration should be inserted right after the includes section and before the UCLASS : class UDataTable; In case you are wondering, in the FindRow line, the second argument (currently not documented on UDataTable function) if the output text to show when something goes wrong so that you know where it comes from.

Chapter 3

  • Page 32 : It's safer if you create an Interface directly. It has changed a lot in the recent years (now version 4.18.2). Instead of creating a class extending Actor, right click on the C++ classes on the Content Browser, and select Create C++ Class. On the list select "Interface". This will create a base. As you can see GENERATED_BODY() instead of those GENERATED macros in the book is a better version. The old style is still valid, but this is the new style. U and I classes are created, but no RPG_API on the U class. Also, no Object.h included, but "CoreMinimal.h", and MinimalAPI on the UINTERFACE macro. Here's the new code:


#pragma once
#include "CoreMinimal.h"
#include "ControllableCharacter.generated.h"

UINTERFACE(MinimalAPI)
class UControllableCharacter : public UInterface
{
GENERATED_BODY()
};

class RPG_API IControllableCharacter
{
GENERATED_BODY()
public:
};

  • Page 33:

  • You could get an error that RPG.h should be included after ControllableCharacter.h (which should be the first)

  • A constructor is not needed anymore:

  • So if you don't need to declare the constructor on the cpp, unless you have to add anything there. In that case, you should declare it public on the h explicitly.

  • Page 34:

  • You need to add #include "ControllableCharacter.h" to the CPP ConstructObject is deprecated from 4.8 . More about instancing objects here. Read 4.8 Release notes : "New: Simplified UObject creation. Only NewObject should be used to create UObjects".


InputComponent = NewObject(UInputComponent::StaticClass(), TEXT("PC_InputComponent0"));

  • Page 36 :

  • Constructor doesn't need : (const class FObjectInitializer& ObjectInitializer) anymore. Just () More functions are created now (tick, setupPlayerInputComponent...) "Implement IControllableCharacter class" means (in case you don't know), inheriting from it :

class RPG_API ARPGCharacter : public ACharacter, public IControllableCharacter

  • Also add #include "ControllableCharacter.h" before the generated.h The code for the Cpp is very different from the one generated nowadays. Just add the four lines (bUse... ) to ARPGCharacter() which is the new style of constructors. Then add the two functions, which are OK. GetCharacterMovement() is not available anymore unless (at around 4.14 changed) you add #include "GameFramework/CharacterMovementComponent.h" explicitly after the first RPGCharacter.h include.

  • Page 37 :

  • We can now use GameModeBase, which is a simpler version of GameMode, in the dropdown menu. GameMode is not available now unless you do it by hand. We need to declare the constructor on the header since now there's nothing else but the macro:


public: ARPGGameMode();

And in the cpp:


ARPGGameMode::ARPGGameMode()
{
    PlayerControllerClass = ARPGPlayerController::StaticClass();
    DefaultPawnClass = ARPGCharacter::StaticClass();
}

  • Page 39 : Instead of creating a new project, go to the Epic Launcher, in the marketplace add Animation Starter Pack which is free, and then in your project list add the pack to your project. Then you will have everything you need there. The name of Hero is now Mannequin. Names have changed a lot since then.

  • Page 40 :

  • FOpen the "FieldPlayer" and on the components list, select Mesh. Then select the SK_Mannekin mesh under Mesh section. On the Animation section you can chose: Use Animation Asset -> Jog Fwd Rifle to see him running. If you select Use Animation Blueprint, and select Hero_TPP_AnimBlueprint on the list , the character will not be moving but Idle.

  • Page 41 : #include "GameFramework/Pawn.h" to use APawn

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Original Author: ()