A constructor has already been declared, but it hasn't?

Hello, I am trying to override the default Character Movement Component (I’m gonna refer to it as “CMC” to keep things short) in my custom character class by using a custom CMC and swapping the two out.

It doesn’t do THAT much, but it just sets the default values that I want to have enabled by default so that when a developer purchases and uses my framework, they don’t get stumped by default configurations that may leave them confused while the answer sits right in front of them.

For example, the switch to enable crouching in the default CMC is buried all the way at the bottom in the nav movement component’s settings, which is something I’d rather not have to put in my instruction manual if I can avoid it (especially considering that with so many games that I play using a crouch feature, I’m surprised this isn’t enabled by default - you guessed it, my override CMC class overrides this to be enabled by default).

The issue is that when I try to compile all of this, Unreal Engine spits out some very weird error that I can’t make sense of:

  C:\Users\willi\OneDrive\Rapidfire\Conniption Framework for Unreal Engine\Framework\Plugins\ConniptionFramework\Source\ConniptionFramework\Public\CF_CharacterMovement.h(17): error C2535: 'UCF_CharacterMovement::UCF_CharacterMovement(const FObjectInitializer &)': member function already defined or declared
  C:\Users\willi\OneDrive\Rapidfire\Conniption Framework for Unreal Engine\Framework\Plugins\ConniptionFramework\Source\ConniptionFramework\Public\CF_CharacterMovement.h(15): note: see declaration of 'UCF_CharacterMovement::UCF_CharacterMovement'
  [2/2] Compile Module.ConniptionFramework.cpp
  C:\Users\willi\OneDrive\Rapidfire\Conniption Framework for Unreal Engine\Framework\Plugins\ConniptionFramework\Source\ConniptionFramework\Public\CF_CharacterMovement.h(17): error C2535: 'UCF_CharacterMovement::UCF_CharacterMovement(const FObjectInitializer &)': member function already defined or declared
  C:\Users\willi\OneDrive\Rapidfire\Conniption Framework for Unreal Engine\Framework\Plugins\ConniptionFramework\Source\ConniptionFramework\Public\CF_CharacterMovement.h(15): note: see declaration of 'UCF_CharacterMovement::UCF_CharacterMovement'

That seemingly should not be happening. I only declared the constructor one time, why is this an issue?

If someone could explain this to me it would be greatly appreciated.

Here is the code for the CUSTOM CMC:

.h

// Copyright Rapidfire Computer Entertainment. All rights reserved.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "CF_CharacterMovement.generated.h"

UCLASS()
class CONNIPTIONFRAMEWORK_API UCF_CharacterMovement : public UCharacterMovementComponent
{
	GENERATED_UCLASS_BODY()

		UCF_CharacterMovement(const FObjectInitializer& ObjectInitializer);
	
};

.cpp

// Copyright Rapidfire Computer Entertainment. All rights reserved.

#include "CF_CharacterMovement.h"

UCF_CharacterMovement::UCF_CharacterMovement(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// Set all of this by default!
	
	
	// Basic movement capabilities.
	NavAgentProps.bCanCrouch = true;// Crouching is used in almost every game so why would this be disabled by default? Come on Epic!
	NavAgentProps.bCanJump = true; // Same as crouching but this one's actually enabled by default, good stuff.
	NavAgentProps.bCanSwim = true; // Same as the jumping/crouching but a little less common it seems.
	NavAgentProps.bCanFly = true; // May use this for a more efficient parkour system so it's important to consider!
	NavAgentProps.bCanWalk = true; // No-brainer, why wouldn't you be able to walk?

	// Ground movement controls.
	SetCrouchedHalfHeight(44.0f);
	SetWalkableFloorAngle(45.0f);
	MaxWalkSpeed = 400.0f;
	MaxWalkSpeedCrouched = 230.0f;
	bCanWalkOffLedgesWhenCrouching = true;

	// Jump controls.
	JumpZVelocity = 330.0f;
	AirControl = 0.24f;

	// Swim controls.
	MaxSwimSpeed = 240.0f;
	OutofWaterZ = 352.0f;

	// Fly controls, even though we really don't use these.
	MaxFlySpeed = 400.0f;

	// Custom movement controls.
	MaxCustomMovementSpeed = 400.0f;

	// Rotation controls.
	RotationRate = FRotator(0.0f, 470.0f, 0.0f);

	// Nav mesh controls.
	bProjectNavMeshWalking = true;
	bProjectNavMeshOnBothWorldChannels = true;

	// Optimization controls.
	bUpdateOnlyIfRendered = true;
	bAutoUpdateTickRegistration = true;
}

I followed the tutorial linked below to do this, since I didn’t know how to myself. It is for Unreal Engine 4 but since it’s C++ and it doesn’t seem like the API has changed much in this area between UE4 and UE5 I went ahead and followed it anyway.

https://www.youtube.com/watch?v=XDYinZb5uaw

The second declaration of the constructor hides behind the GENERATED_UCLASS_BODY macro. If you look at the contents of the CF_CharacterMovement.generated.h file you should find it in there, it is automatically generated by UnrealHeaderTool. Just remove your declaration in the CF_CharacterMovement.h header and it should work.

Thanks, I just switched the macro back to GENERATED_BODY and it compiled fine. I will mark this as the solution if the component functions as intended within the character.

Edit: Great news, everything works perfectly! Proper solution marked; thanks for the help.

1 Like