function already defined

Hi there,
I’m new to UE C++ and I want to write my own MovementComponent.
Unfortunately I get a compiler error, which states that a function is already defined.

I have these two classes:
MovementComponent.h:


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

#pragma once


#include "GameFramework/PawnMovementComponent.h"
#include "ExtensibleMovementMode.h"
#include "ExtensiblePawnMovementComponent.generated.h"

/**
 * 
 */
UCLASS(ClassGroup = (Movement), meta = (BlueprintSpawnableComponent))
class GAME_API UExtensiblePawnMovementComponent : public UPawnMovementComponent
{
	GENERATED_BODY()
private:
	UPROPERTY()
		UExtensibleMovementMode* currentMovementMode;
	UPROPERTY(EditAnywhere)
		float gravityScale = 1.0f;
public:

	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION(BlueprintCallable, Category = "MovementMode")
	UExtensibleMovementMode* setMovementMode(UExtensibleMovementMode* newMovementMode);
};


MovementMode.h


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

#pragma once

#include "UObject/NoExportTypes.h"
#include "ExtensiblePawnMovementComponent.h"
#include "ExtensibleMovementMode.generated.h"

/**
 * 
 */
UCLASS(Abstract,Blueprintable,BlueprintType)
class GAME_API UExtensibleMovementMode : public UObject
{
	GENERATED_BODY()
	public:
		UFUNCTION(BlueprintImplementableEvent)
		void phys(float delta, UExtensiblePawnMovementComponent* movement);
};


MovementComponent.cpp:


#include "ExtensiblePawnMovementComponent.h"

UExtensibleMovementMode* UExtensiblePawnMovementComponent::setMovementMode(UExtensibleMovementMode* newMovementMode)
{
	UExtensibleMovementMode* old = this->currentMovementMode;
	this->currentMovementMode = newMovementMode;
	return old;
}
void UExtensiblePawnMovementComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	UPawnMovementComponent::TickComponent( DeltaTime,  TickType,ThisTickFunction);
}

MovementMode.cpp



#include "ExtensibleMovementMode.h"

void UExtensibleMovementMode::phys(float delta, UExtensiblePawnMovementComponent* movement)
{}




The error says:

But as you can see, I defined the function only once.

I think you are only suppose to declare BlueprintImplementableEvent in the header file and not provide a definition in the cpp file because blueprints are suppose to provide the definition of the function. So remove the definition in the .cpp file and it should compile.

I see, but what If I want the class to be inherited by C++ and Blueprint at the same time?

You would want to use a blueprintnativeevent then.

Here is rama’s wiki on the differences and uses of those two types

https://wiki.unrealengine.com/Blueprints,_Empower_Your_Entire_Team_With_BlueprintNativeEvents

https://wiki.unrealengine.com/Blueprints,_Empower_Your_Entire_Team_With_BlueprintImplementableEvent

Thanks for this clarification!