How to access function from Character from GameMode?

Hello,

I’d like to call the function GetNumResponses (inside my Character-class; gets the number of space-presses that the character has received so far) from my GameMode-class. However, that does not work. Could you please help me with that? Any help is really appreciated!

This is what I have so far:


PD6GameMode.cpp

void APD6GameMode::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);

// get number of space presses that the character has received so far
APD6Character* TestPD6Character = Cast<APD6Character>(ACharacter); // ERROR: type name is not allowed
NumResponses = TestPD6Character->GetNumResponses();

}


PD6Character.h

UCLASS()
class PD6_API APD6Character : public ACharacter
{
GENERATED_BODY()

public:
// other code

    // public way to access the number of responses given by the character
    float GetNumResponses();

protected:
// NumResponses counts the space-presses
UPROPERTY()
float NumResponses;

// increase NumResponses when space key is pressed
UFUNCTION()
	void SetNumResponses();

}


PD6Character.cpp

// Sets default values
APD6Character::APD6Character()
{
PrimaryActorTick.bCanEverTick = true;
NumResponses = 0.f;
}

// Called to bind functionality to input
void APD6Character::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
InputComponent->BindAction(“GoalResponse”, IE_Pressed, this, &APD6Character::SetNumResponses);
}

void APD6Character::SetNumResponses()
{
NumResponses = NumResponses + 1.f;
}

float APD6Character::GetNumResponses()
{
return NumResponses;
}

Assuming that your character is a controlled by the player, you could get it like this …

ACharacter* MyCharacter =   GetWorld()->GetFirstPlayerController()->GetCharacter();
APD6Character* TestPD6Character = CastChecked<APD6Character>(MyCharacter);

Thank you very much, halifacx!! That solved the problem.