I am setting up inputs on my player controller but they will not register at all.
H:
#pragma once
#include "CoreMinimal.h"
#include "Kismet/GameplayStatics.h"
#include "GameFramework/PlayerController.h"
#include "RTSController.generated.h"
class ARTSManager;
class ABuildingManager;
class ARTSPawn;
UCLASS(Blueprintable)
class RTS_API ARTSController : public APlayerController
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
virtual void PlayerTick(float DeltaTime) override;
virtual void SetupInputComponent() override;
public:
void PrintF(float Float);
void PrintB(bool Bool);
void PrintS(FString String);
ARTSManager* RTSManager;
UPROPERTY()
ABuildingManager* BuildingManager;
ARTSPawn* RTSPawn;
AActor* ActorUnderCursor;
FVector CursorTerrainPosition;
FVector2D TileLocation;
bool bBuildMode;
void Init();
void MouseDetection();
FVector2D GetTile();
void LeftClick();
void OnPanCameraRight(float Value);
void OnPanCameraForward(float Value);
};
CPP:
#include "Player/RTSController.h"
#include "BuildingManager.h"
#include "RTSManager.h"
#include "RTSPawn.h"
void ARTSController::BeginPlay()
{
Super::BeginPlay();
RTSPawn = (ARTSPawn*) UGameplayStatics::GetPlayerPawn(this, 0);
//PrintB(InputEnabled());
}
void ARTSController::PlayerTick(float DeltaTime)
{
MouseDetection();
FString Message = TileLocation.ToString();
//GEngine->AddOnScreenDebugMessage(-1, 50, FColor::Blue, Message, true, FVector2D(1));
if (bBuildMode)
RTSManager->BuildingManager->UpdateGhostBuilding();
}
void ARTSController::SetupInputComponent()
{
Super::SetupInputComponent();
bEnableClickEvents = true;
bShowMouseCursor = true;
InputComponent->BindAction("LeftClick", IE_Released, this, &ARTSController::LeftClick);
InputComponent->BindAxis("PanCameraRight", this, &ARTSController::OnPanCameraRight);
InputComponent->BindAxis("PanCameraForward", this, &ARTSController::OnPanCameraForward);
PrintB(InputEnabled());
PrintS("In");
}
void ARTSController::PrintF(float Float)
{
GEngine->AddOnScreenDebugMessage(-1, 50, FColor::Black, GetClass()->GetName() + ": " + FString::SanitizeFloat(Float), true, FVector2D(1));
}
void ARTSController::PrintB(bool Bool)
{
GEngine->AddOnScreenDebugMessage(-1, 50, FColor::Black, GetClass()->GetName() + ": " + (Bool ? "True" : "False"), true, FVector2D(1));
}
void ARTSController::PrintS(FString String)
{
GEngine->AddOnScreenDebugMessage(-1, 50, FColor::Black, GetClass()->GetName() + ": " + String, true, FVector2D(1));
}
void ARTSController::MouseDetection()
{
FHitResult TerrainHit;
GetHitResultUnderCursor(ECollisionChannel::ECC_GameTraceChannel1, false, TerrainHit);
CursorTerrainPosition = TerrainHit.Location;
TileLocation = GetTile();
FHitResult ActorHit;
GetHitResultUnderCursor(ECC_Visibility, false, ActorHit);
ActorUnderCursor = ActorHit.GetActor();
}
FVector2D ARTSController::GetTile()
{
float GridSize = 100;
float X = FMath::FloorToFloat(CursorTerrainPosition.X / GridSize);
float Y = FMath::FloorToFloat(CursorTerrainPosition.Y / GridSize);
return FVector2D(X, Y);
}
void ARTSController::LeftClick()
{
if (bBuildMode)
BuildingManager->PlaceBuilding();
GEngine->AddOnScreenDebugMessage(-1, 50, FColor::Black, "Left click", true, FVector2D(1));
}
void ARTSController::OnPanCameraRight(float Value)
{
RTSPawn->PanRightValue = Value;
}
void ARTSController::OnPanCameraForward(float Value)
{
RTSPawn->PanForwardValue = Value;
}