Player Controller functions not calling

Hi all, I’ve put debug messages in my player controllers functions and none of them except the constructor are calling. If anyone can help, it will be much appreciated, thank you :slight_smile:

Heres the code:

PlayerCharacterController.h:



#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "PlayerCharacterController.generated.h"

class APlayerCharacter;

UCLASS()
class GUARDIANSOFSUNSHINE_API APlayerCharacterController : public APlayerController
{
GENERATED_BODY()

public:
APlayerCharacterController(const FObjectInitializer& PCIP);

// Called every frame
virtual void PlayerTick(float DeltaTime) override;
virtual void Tick(float DeltaTime) override;

void UpdateCharacter();
void UpdateAnimation();

// The paper sprite component that will hold our idle sprite when it is needed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IdleSprite")
class UPaperSpriteComponent* IdleSpriteComponent;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "IdleSprite")
class UPaperSprite* IdleSprite;

// The animated flipbook that will have our walking animation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PaperFlipbook")
class UPaperFlipbookComponent* WalkingComponent;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PaperFlipbook")
class UPaperFlipbook* WalkingAnimation;

// The animated flipbook that will have our jumping animation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PaperFlipbook")
class UPaperFlipbookComponent* JumpingComponent;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PaperFlipbook")
class UPaperFlipbook* JumpingAnimation;

// Player references
UPROPERTY(EditAnywhere)
TSubclassOf<APlayerCharacter> PlayerCharacterObject;

APlayerCharacter* PlayerCharacter;

// Movement functions
UFUNCTION()
virtual void SetupInputComponent() override;

void MoveHorizontal(float Value);

};


PlayerCharacterController.cpp:



#include "PlayerCharacterController.h"

#include "PlayerCharacter.h"
#include "GameFramework/Controller.h"

#include "PaperFlipbookComponent.h"
#include "PaperSpriteComponent.h"

#include "Engine.h"

#define print(text) if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Green, text)

APlayerCharacterController::APlayerCharacterController(const FObjectInitializer& PCIP) : Super(PCIP)
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;

IdleSpriteComponent = PCIP.CreateDefaultSubobject<UPaperSpriteComponent>(this, TEXT("IdleSpriteComponent"));

WalkingComponent = PCIP.CreateDefaultSubobject<UPaperFlipbookComponent>(this, TEXT("WalkingComponent"));

JumpingComponent = PCIP.CreateDefaultSubobject<UPaperFlipbookComponent>(this, TEXT("JumpingComponent"));

// Get a reference to the PlayerCharacter
if (PlayerCharacterObject)
{
PlayerCharacter = Cast<APlayerCharacter>(PlayerCharacterObject);
}
}

void APlayerCharacterController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);

print("PlayerTick");

if (PlayerCharacter)
{
UpdateCharacter();
}
}

void APlayerCharacterController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
print("Tick");
}

void APlayerCharacterController::SetupInputComponent()
{
Super::SetupInputComponent();

EnableInput(this);

print("Input");

InputComponent->BindAxis("MoveHorizontal", this, &APlayerCharacterController::MoveHorizontal);

}

void APlayerCharacterController::MoveHorizontal(float Value)
{
print("Moving");
if (PlayerCharacter)
{
PlayerCharacter->MoveHorizontal(Value);
}
}

void APlayerCharacterController::UpdateAnimation()
{

}

void APlayerCharacterController::UpdateCharacter()
{
// Update animation to match the motion
UpdateAnimation();

const FVector PlayerVelocity = PlayerCharacter->GetVelocity();
float TravelDirection = PlayerVelocity.X;

print(FString::SanitizeFloat(TravelDirection));

}


The most likely scenario is that you haven’t told the GameMode to use your custom Player Controller class.

Thank you so much, that was such a silly mistake of me that I stupidly overlooked, appreciate the time saver :slight_smile: