I’ve been following this series on Youtube (using 4.18.2) and have encountered a scenario I can’t quite figure out yet.
It seems my Projectile check is always returning negative and hence my UE_LOG for the fire event isn’t firing.
My turret.h contains the following:
protected:
// Maximum turn rate in degrees/second for the turret.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Turret")
float YawSpeed;
// Tank that owns this turret.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Turret")
ATank* Tank;
// Projectile to spawn when firing.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Turret")
TSubclassOf<AActor> Projectile;
And turret.cpp has the following code for the the fire action:
const FTankInput& CurrentInput = Tank->GetCurrentInput();
if (CurrentInput.bFire1)
{
UE_LOG(LogTemp, Warning, TEXT("FIRE! 1"));
}
if (CurrentInput.bFire1 && Projectile)
{
UE_LOG(LogTemp, Warning, TEXT("FIRE! 2"));
if (UWorld* World = GetWorld())
{
UE_LOG(LogTemp, Warning, TEXT("FIRE! 3"));
if (AActor* NewProjectile = World->SpawnActor(Projectile))
{
FVector Loc = TurretSprite->GetSocketLocation("Muzzle");
FRotator Rot = TurretDirection->GetComponentRotation();
NewProjectile->SetActorLocation(Loc);
NewProjectile->SetActorRotation(Rot);
}
}
}
However **FIRE! 1 **is working fine, and shows in my logs. But Fire! 2 is not, implying the check on Projectile is failing, and I can’t figure why that would be the case here. Any ideas?