Download

Tutorials outdated?

Hi, I’m following this tutorial: https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial

Though even the first step of the code bit about adding the code to the headers is giving me errors. The autogenerated class has like no constructor for .cpp and the header file has an error for the FPSGameMode.generated.h file in #include.

Code here:


#pragma once

#include "GameFramework/GameMode.h"
#include "FPSGameMode.generated.h"

UCLASS()
class FPSPROJECT_API AFPSGameMode : public AGameMode
{
	GENERATED_BODY()

	virtual void StartPlay() override;
};

Error here:
7da89667b99fb20f34017f5b021b571d182ac858.png

Its quite common to see errors with the generated include files if you have other errors, that’s because they probably haven’t been generated yet (they are generated when you build) because of the other errors prevent it from ever getting to that point. At first glance, your code seems fine, but do you have the associated ‘.cpp’ file also created? If so can you show it?

Thanks for the quick reply, here’s my code for the .cpp:



#include "Engine.h"
#include "FPSProject.h"
#include "FPSGameMode.h"

AFPSGameMode::AFPSGameMode(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) {
	
}

void AFPSGameMode::BeginPlay() {
	Super::BeginPlay();

	StartMatch();

	if (GEngine) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}


Errors:
cb295158a93d2bd26e69d1c2d2de16650d24f198.png
46f60d08e658f92e7e8d22e3f6ca37245ab034ad.png

Edit:
The weird thing is, it is saying the class “UVertexAnimBase” but the Super::BeginPlay() should be referring to FPSGameMode.h’s BeginPlay() void. I tried it with StartPlay() and I got an error, I think it’s the same error.

Since version 4.6 you need to explicitly declare a constructor in your header file if you want to overwrite it. In addition you need to use FObjectInitializer instead of FPostConstructInitializeProperties, both explained in this thread: https://forums.unrealengine.com/showthread.php?55256-Problem-with-quot-Introduction-to-UE4-Programming-quot-on-Mac-with-XCode

I guess you are using the latest version of the engine, which would make FPostConstructInitializeProperties deprecated.
It’s FObjectInitializer now.

The following code should be working:



//MyGameMode.h
UCLASS()
class THIRDPERSONTUTORIAL_API AMyGameMode : public AGameMode
{
public:
	GENERATED_BODY()
	AMyGameMode(const class FObjectInitializer& PCIP);	
	virtual void StartPlay() override;
};




//MyGameMode.cpp
AMyGameMode::AMyGameMode(const class FObjectInitializer& PCIP) 
: Super(PCIP)
{

}

void AMyGameMode::StartPlay()
{
	Super::StartPlay();
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}


Thanks, I tried updating that but then I saw the below code and tried that as it is pretty much what you said.

Thanks for the help, here’s my new code:

FPSGameMode.h


#include "GameFramework/GameMode.h"
#include "FPSGameMode.generated.h"

UCLASS()
class FPSPROJECT_API AFPSGameMode : public AGameMode {
public:
	GENERATED_UCLASS_BODY()
	AFPSGameMode(const class FObjectInitializer& PCIP);

	virtual void StartPlay() override;
};


FPSGameMode.cpp



#include "FPSProject.h"
#include "FPSGameMode.h"

AFPSGameMode::AFPSGameMode(const class FObjectInitializer& PCIP) : Super(PCIP) {
	
}

void AFPSGameMode::StartPlay() {
	Super::StartPlay();

	StartMatch();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}


Edit: Never mind, no more errors. Fixed as said below.

Never mind, thanks both of you, it works! I just had to build it a few times before my Visual Studio realised it was fine.

One thing is, I’m using GENERATED_UCLASS_BODY() in my header file yet Skynet, you used GENERATED_BODY(). What’s the difference? I don’t want to change my code to use GENERATED_BODY() yet incase it messes up again. :confused:

Finally, I can’t find any other FPS tutorials for Unreal Engine that are completely up-to-date. :frowning: Does anyone know of any? I won’t ever be using UE4 below version 4.6 so there’s not much point of me knowing UE4 4.3 code.

GENERATED_UCLASS_BODY() is the old macro which is deprecated since version 4.6. When you use it you don’t need to declare your constructor in the header file but you always have to override the default constructor. In addition you use FPostConstructInitializeProperties.

GENERATED_BODY() is the newer version where you explicitly have to declare the constructor in the header file if you want to override it. In addition you use FObjectInitializer.

A brief explanation on how to use the newer version can be found here: https://forums.unrealengine.com/showthread.php?52236-4-6-constructor-changes-am-confused&p=181552&viewfull=1#post181552

Oh thankss, I think I get it now. That fixed 4/4 of my errors.