Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Problems with the Spawner timer manager

Author: Luis Lugo Rosas

Posted: 03/21/2025

This week, I encountered an issue while implementing an enemy spawner using GetWorld()->GetTimerManager()->SetTimer(). My goal was to spawn enemies at a set rate until a maximum number was reached. However, instead of stopping when the limit was met, the spawner continued to spawn enemies indefinitely. This occurred because the timer kept executing the spawn function without properly checking if the maximum count had been reached before scheduling the next spawn. If left unaddressed, this bug would lead to an uncontrolled enemy population, negatively impacting both gameplay balance and performance. Players could be overwhelmed by excessive enemies, and the game might experience frame rate drops due to the increasing number of spawned actors. Fixing this issue is crucial to ensure smooth and predictable enemy waves, maintaining both gameplay fairness and performance stability.


The issue arose from the handling of spawn logic within the timer system. Initially, I tried using a while loop inside BeginPlay() to continuously spawn enemies while bIsSpawning remained true. However, this caused Unreal to crash because the loop blocked execution instead of properly utilizing the timer system. Realizing this, I transferred the spawn logic into the function bound to the timer, implementing an if statement to stop spawning once the maximum enemy count was reached. Unfortunately, this method only allowed one enemy to spawn, preventing further spawns thereafter.

To fix this, I created a private function responsible for the bIsSpawning check separately. This function assessed whether spawning should continue and then called the actual spawn function if the conditions were satisfied. I bound this new function to the timer, ensuring that it would check the conditions at each interval without disrupting the spawning loop or exceeding the limit. This solution prevents enemy overflow while maintaining a steady spawn rate, ensuring a balanced gameplay experience and stable performance.

Support this post

Did you like this post? Tell us