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.