Hey,
I had a weird error when I first used spawnpoint and had to re install UE to get BattleTank working again I had to update to 4.22 (I was on 4.21.2) and my UI is suppost to load when the aiming component is found (Event Found Aiming Component) that has the BP Aiming Comp Ref on and the UI no longer works but the aiming component is loading
here’s my player controller + Blueprint
Blueprint
// © Neonzz game studios
#include "MyTankPlayerController.h"
#include "BattleTank.h"
#include "TankAimingComponant.h"
#include "Tank.h"
void AMyTankPlayerController::BeginPlay()
{
Super::BeginPlay();
auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponant>();
if (AimingComponent)
{
FoundAimingComponent(AimingComponent);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Warning no Aiming Componant"))
}
}
void AMyTankPlayerController::Tick(float DeltaTime)
{
Super::Tick( DeltaTime );
AimTowardsCrosshair();
}
void AMyTankPlayerController::SetPawn(APawn * InPawn)
{
Super::SetPawn(InPawn);
if (InPawn)
{
auto PossessedTank = Cast<ATank>(InPawn);
if (!ensure(PossessedTank))
{
return;
}
PossessedTank->OnTankDeath.AddUniqueDynamic(this, &AMyTankPlayerController::OnPossessedTankDeath);
}
}
void AMyTankPlayerController::OnPossessedTankDeath()
{
StartSpectatingOnly();
}
void AMyTankPlayerController::AimTowardsCrosshair() const
{
if (!GetPawn())
{
return;
}
auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponant>();
if (!ensure(AimingComponent))
{
return;
}
FVector OutHitLocation;
bool bHasGotHitLocation = GetSightRayHitLocation(OutHitLocation);
if (bHasGotHitLocation)
{
AimingComponent->AimAt(OutHitLocation);
}
}
bool AMyTankPlayerController::GetSightRayHitLocation(FVector & OutHitLocation) const
{
int32 ViewportSizeX, ViewportSizeY;
GetViewportSize(ViewportSizeX, ViewportSizeY);
auto ScreenLocation = FVector2D(ViewportSizeX * CrosshairXLocation, ViewportSizeY * CrosshairYLocation);
FVector LookDirection;
if (GetLookDirection(ScreenLocation, LookDirection))
{
return GetLookVectorHitLocation(LookDirection, OutHitLocation);
}
return true;
}
bool AMyTankPlayerController::GetLookDirection(FVector2D ScreenLocation, FVector & LookDirection) const
{
FVector CameraLocation;
return DeprojectScreenPositionToWorld(ScreenLocation.X, ScreenLocation.Y, CameraLocation, LookDirection);
}
bool AMyTankPlayerController::GetLookVectorHitLocation(FVector LookDirection, FVector & OutHitLocation) const
{
FHitResult HitResult;
auto StartLocation = PlayerCameraManager->GetCameraLocation();
auto EndLocation = StartLocation + (LookDirection * LineTraceRange);
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECollisionChannel::ECC_Camera))
{
OutHitLocation = HitResult.Location;
return true;
}
OutHitLocation = FVector(0, 0, 0);
return false; //line trace failed
}