Posted September 26, 2025 by JoseanRodriguez
#GameDev #IndieDev #UnrealEngine #Devlog #WaveBreakers
The Problem
This week I ran into a bug that felt more like a ghost story than a coding issue. While testing enemy pathfinding, my agents suddenly stopped mid‑lane and refused to move forward. After some digging, I realized they were trying to attack a phantom tower — an invisible structure that didn’t exist in the editor but still showed up in the AI’s targeting logic.
For players, this would have been a disaster. Enemies freezing in place breaks the flow of the wave defense gameplay and makes the round unplayable. To make matters worse, if I tried to move this phantom tower in the editor, the game would crash instantly. It was like the ghost didn’t want to be disturbed.
What was really happening
Under the hood, this wasn’t supernatural at all (though it sure felt like it).
The Solution
After tracing the issue, I discovered the root cause: the AI was holding onto a stale reference to a destroyed tower actor. Even though the tower no longer existed, the reference wasn’t cleaned up, so the targeting system still thought it was valid. When the AI tried to interact with it, Unreal dereferenced an invalid pointer, which caused the crash.
To fix this, I added defensive checks (IsValid()
and IsPendingKill()
) in the AI’s targeting loop so enemies skip over destroyed actors. I also updated the tower destruction logic to clear itself out of manager lists when removed, preventing ghost references from lingering. As a quick workaround, I also nudged the lane path so it no longer intersected the phantom’s old haunt.
With these fixes, enemies now march smoothly toward their real objectives, and the game no longer crashes when interacting with destroyed towers. For players, this means a more reliable wave defense experience without enemies getting stuck or the game suddenly breaking.
Takeaway
Debugging AI often feels like ghost hunting. This time, the “phantom tower” taught me two lessons: