I get this on newer versions of UE 4.24, but not on older ones around 4.17.
Do I have to make something public? Do I ever edit the default Pawn.h class?
GameFramework/PawnMovementComponent.h(14): note: see declaration of ‘APawn’
BaseCharacter.cpp(141) : error C2248: ‘APawn::PlayerState’: cannot access private member declared in class ‘APawn’
GameFramework/Pawn.h(131): note: see declaration of ‘APawn::PlayerState’
My BaseCharacter.cpp file
#include "BaseCharacter.h"
#include "TPS2.h"
#include "PlatformerPlayerState.h"
#include "Net/UnrealNetwork.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/ArrowComponent.h"
#include "Components/InputComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/Controller.h"
// Sets default values
ABaseCharacter::ABaseCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//Set up our springarm to hold our camera
SpringArm = CreateDefaultSubobject<USpringArmComponent>(FName("Camera Boom"));
//Do not allow spring arm to rotate with character
SpringArm->bUsePawnControlRotation = false;
//Do not allow it to be affected by relative rotation of character
SpringArm->SetUsingAbsoluteRotation(true);
//Length of arm
SpringArm->TargetArmLength = 700.f;
//Attach to root
SpringArm->SetupAttachment(RootComponent);
//Set up the camera
Camera = CreateDefaultSubobject<UCameraComponent>(FName("Camera"));
//Give it a wider FOV
Camera->FieldOfView = 110.f;
//attach to SpringArm
Camera->SetupAttachment(SpringArm);
//Set up our forward direction
TraceDirection = CreateDefaultSubobject<UArrowComponent>(FName("Trace Direction"));
//attach to root
TraceDirection->SetupAttachment(RootComponent);
//set up basic network replication
bReplicates = true;
bAlwaysRelevant = true;
//bReplicateMovement = true;
SetReplicatingMovement(true);
//Set up character movement properties
//rotate the character in the direction its moving
GetCharacterMovement()->bOrientRotationToMovement = true;
//don't rotate based on controller input
bUseControllerRotationPitch = false;
bUseControllerRotationRoll = false;
bUseControllerRotationYaw = false;
//jump higher
GetCharacterMovement()->JumpZVelocity = 1000.f;
//fall faster
GetCharacterMovement()->GravityScale = 2.f;
//Allow some control of character while airborne
GetCharacterMovement()->AirControl = 0.8f;
}
void ABaseCharacter::MoveForward(float amount)
{
//add movement input in the direction the camera is facing
if (Controller && amount) {
AddMovementInput(SpringArm->GetForwardVector(), amount);
}
}
void ABaseCharacter::MoveRight(float amount)
{
if ((Controller != NULL) && (amount != 0.0f))
{
// find out which way is right
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get right vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// add movement in that direction
AddMovementInput(Direction, amount);
}
}
void ABaseCharacter::RotateCamera(float amount)
{
//add rotation on the spring arm's z axis
if (Controller && amount) {
FVector rot = SpringArm->GetComponentRotation().Euler();
rot += FVector(0, 0, amount);
SpringArm->SetWorldRotation(FQuat::MakeFromEuler(rot));
}
}
void ABaseCharacter::ChangeCameraHeight(float amount)
{
//add rotation on spring arm's y axis. Clamp between -45 and -5
if (Controller && amount) {
FVector rot = SpringArm->GetComponentRotation().Euler();
float originalHeight = rot.Y;
originalHeight += amount;
originalHeight = FMath::Clamp(originalHeight, -45.f, -5.f);
rot = FVector(0, originalHeight, rot.Z);
SpringArm->SetWorldRotation(FQuat::MakeFromEuler(rot));
}
}
void ABaseCharacter::CollectCoin()
{
APlatformerPlayerState *PS = Cast<APlatformerPlayerState>(PlayerState);
if (PS) {
PS->CollectCoin();
}
}
// Called when the game starts or when spawned
void ABaseCharacter::BeginPlay()
{
Super::BeginPlay();
//set the spring arm behind our character
SpringArm->SetRelativeRotation(FQuat::MakeFromEuler(FVector(0, -25, 180)));
}
// Called every frame
void ABaseCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ABaseCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//Bind inputs
InputComponent->BindAction("Jump", EInputEvent::IE_Pressed, this, &ACharacter::Jump);
InputComponent->BindAxis("ChangeCameraHeight", this, &ABaseCharacter::ChangeCameraHeight);
InputComponent->BindAxis("RotateCamera", this, &ABaseCharacter::RotateCamera);
InputComponent->BindAxis("MoveForward", this, &ABaseCharacter::MoveForward);
InputComponent->BindAxis("MoveRight", this, &ABaseCharacter::MoveRight);
}