Unity Sentry-Gemini Debugger: How We Automated Game Bug Smashes with Sentry and AI
This post is submitted for the DEV’s Summer Bug Smash Challenge (Smash Stories / Best Use of Sentry / Best Use of Google AI categories).
๐ The Bug
While playtesting our latest Unity game, we hit a frustrating, intermittent crash. The game would freeze, and our console log was cluttered with a cryptic NullReferenceException. Because the crash occurred randomly during game state changes, finding the exact script reference and state corruption manually was like looking for a needle in a haystack.
๐ The Discovery
Fortunately, we had Sentry integrated into our build. An alert fired on our Sentry dashboard, pinpointing the issue:
-
Error:
NullReferenceException: Object reference not set to an instance of an object -
Location:
PlayerController.csinUpdate()at line 42.
Sentry gave us the trace, but we still faced a developer’s daily friction: opening the codebase, finding the script, scrolling to line 42, analyzing the context, and writing the fix. This manual cycle felt too slow.
๐ต๏ธโโ๏ธ The Investigation & The Tool We Built
We wanted to automate this friction away. So, we built a custom tool directly inside the game engine: Unity Sentry-Gemini Debuggerโa lightweight Unity Editor extension.
We designed it with zero external DLL dependencies to prevent assembly conflicts in Unity. Using C# and regex:
- It queries the Sentry API to retrieve the latest project crashes and stack traces inside the Editor.
- It automatically matches the stacktrace to our local script (
PlayerController.cs) and renders a live code preview of the crash site. - It compiles the context (Sentry error + local code) and queries Google Gemini API for an immediate fix.
๐ The Resolution
We launched our new editor tool (Window > Sentry-Gemini Debugger), fetched the active Sentry issue, and clicked Analyze with Gemini.
Gemini instantly detected that we were attempting to access a UI component ref that hadn’t been initialized during Awake() when the game state reloaded. It provided the corrected code block.
We clicked Apply C# Fix. The tool:
- Created a
.bakbackup ofPlayerController.cs. - Overwrote the code with the fix.
- Triggered a native Unity compilation reimport.
The bug was smashed, the script recompiled, and playtests resumedโall in under 15 seconds without leaving the Unity Editor!
๐ ๏ธ Tech Stack & Open Source Code
- Language: C# (Unity Editor scripting)
- API integrations: Sentry Web API & Google Gemini API
- GitHub Repository: https://github.com/batu-ta/unity-sentry-gemini-debugger
๐ก What We Learned (Sentry & AI Impact)
By bridging real-time error tracking (Sentry) and generative AI (Gemini) directly inside the Unity Engine, we turned debugging from a detective chore into a one-click automation.
๋ต๊ธ ๋จ๊ธฐ๊ธฐ