I’m extremely new to UE5 and C++ and I got a couple errors after trying to edit the player controller cpp and header files.
Here is my cpp file:
// Copyright Epic Games, Inc. All Rights Reserved.
include “CPPTutorialBasicsPlayerController.h”
include “GameFramework/Pawn.h”
include “Blueprint/AIBlueprintHelperLibrary.h”
include “NiagaraSystem.h”
include “NiagaraFunctionLibrary.h”
include “CPPTutorialBasicsCharacter.h”
include “Engine/World.h”
include “EnhancedInputComponent.h”
include “InputActionValue.h”
include “EnhancedInputSubsystems.h”
include “Engine/LocalPlayer.h”
DEFINE_LOG_CATEGORY(LogTemplateCharacter);
void ACPPTutorialBasicsPlayerController::BeginPlay()
{
// Call the base class
Super::BeginPlay();
//Add Input Mapping Context
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
}
void ACPPTutorialBasicsPlayerController::SetupInputComponent()
{
// set up gameplay key bindings
Super::SetupInputComponent();
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = Cast(InputComponent)) {
EnhancedInputComponent->BindAction(MovementInput, ETriggerEvent::Triggered, this, &ACPPTutorialBasicsPlayerController::Move);
}
}
void ACPPTutorialBasicsPlayerController::Move(const FInputActionValue &Value)
{
FVector2D MovementVector = Value.Get();
FVector InputVector = FVector(MovementVector, 0);
GetPawn()->AddMovementInput(InputVector, speed, false);
}
H:
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
include “CoreMinimal.h”
include “Templates/SubclassOf.h”
include “GameFramework/PlayerController.h”
include “CPPTutorialBasicsPlayerController.generated.h”
/* Forward declaration to improve compiling times */
class UNiagaraSystem;
class UInputMappingContext;
class UInputAction;
DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All);
UCLASS()
class ACPPTutorialBasicsPlayerController : public APlayerController
{
GENERATED_BODY()
public:
ACPPTutorialBasicsPlayerController();
// MappingContext //
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = “true”))
class UInputMappingContext* DefaultMappingContext;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = “true”))
class UInputAction* MovementInput;
protected:
/** True if the controlled character should navigate to the mouse cursor. **/
uint32 bMoveToMouseCursor : 1;
virtual void SetupInputComponent() override;
// To add mapping context
virtual void BeginPlay();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=“Speed”, meta=(AllowPrivateAccess=“true”))
float speed;
void Move(const FInputActionValue& Value);
};
And the errors:
error C2597: illegal reference to non-static member ‘ACPPTutorialBasicsPlayerController::speed’
error C2352: ‘AController::GetPawn’: a call of a non-static member function requires an object
error C2511: ‘void ACPPTutorialBasicsPlayerController::Move(const FInputActionValue &)’: overloaded member function not found in ‘ACPPTutorialBasicsPlayerController’