War Pigs Devlog: Auto Play Not Stopping When the Match Ends
Author: Jeremy Cahill
The Problem:
Auto Play was built as a toggleable repeating timer that automatically clicks the top player card every few seconds, so testers wouldn't have to manually click through every single round. The issue was that this timer had no awareness of when the actual match ended. Once a player's or enemy's deck hit zero cards and the win/lose results screen appeared, the timer kept firing in the background, still trying to click cards that no longer mattered, essentially fighting with the results screen that had just taken over the input mode.
The Fix:
The real fix was making sure the same function that already detects the end of the game is also responsible for shutting Auto Play off. CheckForGameEnd() runs at the end of every single round already, so it was the natural place to intercept this before the win/lose screen ever shows up.
void AWarPigsDefaultGameMode::CheckForGameEnd()
{
const int32 PlayerCount = PlayerDeck ? PlayerDeck->GetRemainingCardCount() : 0;
const int32 EnemyCount = EnemyDeck ? EnemyDeck->GetRemainingCardCount() : 0;
if (PlayerCount <= 0 || EnemyCount <= 0)
{
if (bAutoPlayEnabled)
{
bAutoPlayEnabled = false;
GetWorldTimerManager().ClearTimer(AutoPlayTimer);
UE_LOG(LogTemp, Warning, TEXT("AutoPlay DISABLED automatically due to game end"));
}
UAudioManager* AudioManager = GetGameInstance()->GetSubsystem<UAudioManager>();
if (APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
if (AWarPigsPlayerController* WPC = Cast<AWarPigsPlayerController>(PC))
{
if (PlayerCount <= 0)
{
if (AudioManager)
{
AudioManager->PlayBasicSound(GetWorld(), PlayerGameLoseSound);
}
WPC->HandleLose();
}
else if (EnemyCount <= 0)
{
if (AudioManager)
{
AudioManager->PlayBasicSound(GetWorld(), PlayerGameWinSound);
}
WPC->HandleWin();
}
}
}
}
}
The flag is set directly to false and the timer is cleared right away, rather than routing through the normal toggle function. This avoids any chance of the toggle logic accidentally flipping Auto Play back on if the end-of-game check happens to run more than once in a single frame.
Other Fixes That Went In Alongside This:
- Auto Play round safety: the auto-click tick already checks whether a round is currently resolving before firing, so it never tries to click mid-War or mid-reveal. This end-of-game fix closes the one remaining gap where it kept running past the actual end of the match.
- Hotkey toggle: added a dedicated input action so Auto Play can be switched on or off with a single keypress, in addition to typing the toggle command into the console.
What's Next:
With Auto Play now correctly respecting both round state and match state, the next pass is tuning how fast it plays so it feels like a natural pace instead of either too slow or too rushed during longer test sessions.
Thanks for following along!
