DEV Community

Batuhan
Batuhan

Posted on

Unity Sentry-Gemini Debugger - Smash Unity Crashes with One-Click AI Fixes πŸ› οΈπŸ€–

Summer Bug Smash: Smash Stories πŸ›πŸ›Ή

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.cs in Update() 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:

  1. It queries the Sentry API to retrieve the latest project crashes and stack traces inside the Editor.
  2. It automatically matches the stacktrace to our local script (PlayerController.cs) and renders a live code preview of the crash site.
  3. 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:

  1. Created a .bak backup of PlayerController.cs.
  2. Overwrote the code with the fix.
  3. 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


πŸ’‘ 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.

Top comments (0)