Hello. I’m trying to call a function from my Pawn inside the Pawn’s attached MovementComponent.
Here’s a simplified version of what I’m trying to do:
MyPawn.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"
class GAME_API AMyPawn : public APawn
{
GENERATED_BODY()
public:
float Get_MovementInputForward() const;
protected:
float MoveInputForward;
void AddMoveForwardInput(float AxisValue);
Pawn.cpp
#include "MyGame.h"
#include "MyPawn.h"
#include "MyPawnMovementComponent.h"
AMyPawn::AMyPawn()
{
// Create an instance of our movement component, and tell it to update the root.
OurMovementComponent = CreateDefaultSubobject<UMyPawnMovementComponent>(TEXT("MyPawnMovementComponent"));
OurMovementComponent->UpdatedComponent = RootComponent;
}
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
InputComponent->BindAxis("MoveForward", this, &AMyPawn::AddMoveForwardInput)
}
void AMyPawn::AddMoveForwardInput(float AxisValue)
{
MoveInputForward = FMath::Clamp<float>(AxisValue, -1.0f, 1.0f);
}
float AMyPawn::Get_MovementInputForward() const
{
return MoveInputForward;
}
MyPawnMovementComponent.h
#include "GameFramework/PawnMovementComponent.h"
#include "MyPawn.h"
#include "MyPawnMovementComponent.generated.h"
UCLASS(ClassGroup = Movement, meta = (BlueprintSpawnableComponent), ShowCategories = (Velocity))
class MyGame UMyPawnMovementComponent : public UPawnMovementComponent
{
GENERATED_UCLASS_BODY()
//GENERATED_BODY()
public:
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
protected:
float PlayerMoveInputForward
virtual void GetPlayerInput() const;
virtual void PreformMove(float playerInputForward) const;
MyPawnMovementComponent.cpp
#include "MyGame.h"
#include "MyPawnMovementComponent.h"
void UMyPawnMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
GetPlayerInput();
PreformMove(PlayerInputForward);
}
void UMyPawnMovementComponent::GetPlayerInput() const
{
PlayerMoveInputForward = // <-- This is the point where I don't know what to do.
}
Does anyone know how I can call Get_MovementInputForward() from AMyPawn inside of UMyPawnMovementComponent? I’ve tried googling around trying to find the proper way to do this. But every method I’ve found results in a compile error.
Any help would be much appreciated!
-Headstub