Code Error Member Function can't be redeclared outside of it's class

So I was following this tutorial and I was following it nicely not getting any errors until now.

// Called when the game starts or when spawned
void AFPSCharacter::BeginPlay()
{
	Super::BeginPlay();
	
	if (GEngine)
	{
		//put up a debug message for 5 seconds. the -1 "Key" value (first arguement) indicates we never need to update or refresh this message
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("We are using FPSCharacter"));
	}

}

The code block above is in FPSCharacter.cpp and it is giving me an error where void AFPSCharacter::BeginPlay() is, saying that BeginPlay() function can not be redeclared outside it’s function. I am relatively new to C++ still and I would like help as this is halting all my progress at the moment.

Hello Nathan,

I’m not sure why it would be giving you this error with this context. Could you post the full .cpp and .h files? It may be easier to paste them on a third party website like pastebin.com and then link them here.

here is my full code

Hm, it could be one of those situations where it’s giving the wrong error and throwing us off. One thing I did notice is that you’re using GEngine without including Engine.h. Could you try including that and see if that changes anything?

In looking in your code on pastebin I noticed you’ve neglected to include the closing brace on your constructor:

// Sets default values
AFPSCharacter::AFPSCharacter()
{
    // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
 
    //Create a first person camera component
    FPSCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
    //Attach the camera component to our capsule component
    FPSCameraComponent->AttachTo(GetCapsuleComponent());
    //Position the camera slightly above the eyes
    FPSCameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f + BaseEyeHeight));
    //Allow the pawn to control camera rotation
    FPSCameraComponent->bUsePawnControlRotation = true;
 
    // Create a first person mesh component for the owning player.
    FPSMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FirstPersonMesh"));
    // Only the owning player sees this mesh.
    FPSMesh->SetOnlyOwnerSee(true);
    // Attach the FPS mesh to the FPS camera.
    FPSMesh->AttachTo(FPSCameraComponent);
    // Disable some environmental shadowing to preserve the illusion of having a single mesh.
    FPSMesh->bCastDynamicShadow = false;
    FPSMesh->CastShadow = false;
 
    // The owning player doesn't see the regular (third-person) body mesh.
    GetMesh()->SetOwnerNoSee(true);

//<<--- OOPS!

// Called when the game starts or when spawned
void AFPSCharacter::BeginPlay()
{
    Super::BeginPlay();

Close the constructor and you should be fine.

Alrighty, let me do that and see if its the only problem, didn’t notice

So I added the changes and I still get errors, here is my visual studio log

1>------ Build started: Project: FPSProject, Configuration: Development_Editor x64 ------
1> Creating makefile for hot reloading FPSProjectEditor (working set of source files changed)
1> Compiling game modules for hot reload
1> Parsing headers for FPSProjectEditor
1> Running UnrealHeaderTool “C:\Users\user\Documents\Unreal Projects\FPSProject\FPSProject.uproject” “C:\Users\user\Documents\Unreal Projects\FPSProject\Intermediate\Build\Win64\FPSProjectEditor\Development\FPSProjectEditor.uhtmanifest” -LogCmds=“loginit warning, logexit warning, logdatabase error” -Unattended -WarningsAsErrors -installed
1> C:/Users/user/Documents/Unreal Projects/FPSProject/Source/FPSProject/FPSCharacter.h(47) : Unknown variable specifier ‘VisibleDefaultsOny’
1>Error : Failed to generate code for FPSProjectEditor - error code: OtherCompilationError (5)
1> UnrealHeaderTool failed for target ‘FPSProjectEditor’ (platform: Win64, module info: C:\Users\user\Documents\Unreal Projects\FPSProject\Intermediate\Build\Win64\FPSProjectEditor\Development\FPSProjectEditor.uhtmanifest).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3075: The command ““C:\Program Files\Epic Games\4.13\Engine\Build\BatchFiles\Build.bat” FPSProjectEditor Win64 Development “C:\Users\user\Documents\Unreal Projects\FPSProject\FPSProject.uproject” -waitmutex” exited with code 5. Please verify that you have sufficient rights to run this command.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ah good catch, I didn’t see that. I hope that’s the only issue.

The key to that error is here:

C:/Users/user/Documents/Unreal Projects/FPSProject/Source/FPSProject/FPSCharacter.h(47) : Unknown variable specifier 'VisibleDefaultsOny'

The error actually happens on line 51 in your UPROPERTY macro for FPSMesh:

    //First-person mesh (arms) only visible to the owning player
    UPROPERTY(VisibleDefaultsOny, Category = Mesh)
    USkeletalMeshComponent* FPSMesh;

“VisibleDefaultsOny” is missing the “l” in “Only”