Download

Wiki tutorial makin a FPS for 4.7.5

Hi,

so I want to make a little oculus rift demo, I have no prior experience with game dev, this is my first day.
I’m following this tutorial : https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial#Creating_a_GameMode
my 3 month c++ course is also years behind me.
I’m develloping (is that even the correct term?) with unreal ungine 4.7.5

So I redefined the constructor as the tuto said



AFPSGameMode::AFPSGameMode(const class FObjectInitializer & ObjectInitializer)
	: Super(ObjectInitializer)
{
	Super::StartPlay();

	StartMatch();

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


However it also said that

and at compilation (from UE4) I get :



Info  FPSGameMode.h(14)  : see declaration of 'AFPSGameMode::AFPSGameMode'
Error  FPSGameMode.h(16)  : error C2535: 'AFPSGameMode::AFPSGameMode(const FObjectInitializer &)' : member function already defined or declared
Info   FPSGameMode.h(14)  : see declaration of 'AFPSGameMode::AFPSGameMode'
Error FPSGameMode.cpp(7)  : error C2084: function 'AFPSGameMode::AFPSGameMode(const FObjectInitializer &)' already has a body
Info   FPSGameMode.h(14)  : see previous definition of '{ctor}'
Error FPSGameMode.h(16)  : error C2535: 'AFPSGameMode::AFPSGameMode(const FObjectInitializer &)' : member function already defined or declared


So I’m guessing that it’s as they said, constructor procedure as changed.
I tried commenting the constructor declaration that the tutorial made me add in the .h since the log
says that it is already declared.

And I’m only getting this error during compilation :



Error FPSGameMode.cpp(7)  : error C2084: function 'AFPSGameMode::AFPSGameMode(const FObjectInitializer &)' already has a body


So apparently the constructor is already implemented in 4.7.5 and you can’t touch it, fine but
What do I do? I’m lost

The tutorial wants me to display a yellow text at the beginning of a game launch.

Thanks.

Hello voxely,

it seems to me that you may be a little confused about the difference between declaration and definition. The code you give is hopefully in the .cpp and meant to be a definition. In this case, get rid of the “class” keyword in your function signature, like so :


AFPSGameMode::AFPSGameMode(const FObjectInitializer & ObjectInitializer)

With the “class” the compiler thinks you want to do a forward declaration of the FObjectInitializer class and hence the error.

You also got confused by the code. Look carefully at the tutorial again, you want the constructor to be an empty function and the rest of the code in the startplay function of your game mode. Bad things (or at least not what you want) will happen if you try to call this in the constructor.

If you still get compiler errors please provide all code in your header and source file.

yes you are right, I’m a little confused by the c++ syntax, I only coded in java for the last 3 years.

in the end you get this :

.cpp



// Fill out your copyright notice in the Description page of Project Settings.

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

AFPSGameMode::AFPSGameMode(const class FObjectInitializer & ObjectInitializer)
	: Super(ObjectInitializer)
{


}

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

	StartMatch();

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


.h



// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

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

/**
 * 
 */
UCLASS()
class FPSPROJECT_API AFPSGameMode : public AGameMode
{
	GENERATED_UCLASS_BODY()
	
public:
	virtual void StartPlay() override;
	
};


Thanks