Bryan Bedard's Blog
My adventures in software development, mistakes and all.

How to Debug Android Games in Unity With logcat

Posted by Bryan Bedard - 1/14/2025

The debugging experience with the Unity player inside the Unity editor is quite good. Many developers use Visual Studio as their script editor for Unity. In Visual Studio you can attach the debugger to Unity and you can set breakpoints in your scripts, step through code and inspect variables. For most testing and debugging it is sufficient to test within the player, even if the game is being built for other platforms such as Android or iOS. However, sometimes the game behaves slightly differently on a particular platform and you may need to test and debug on that platform directly, such as on a mobile device. For Android games, you can connect a device to your development machine with a USB cable and use logcat to inspect debug log output. While not as powerful as being able to set breakpoints, this is a simple way to get visibility into what is happening at runtime in your game.

This article does not cover how to enable debugging on your Android device but you can find other articles easily such as Configure on-device developer options on the Android developer site.

Once you have USB debugging enabled on your device and the Android development tools installed on your development machine, connect your Anrdoid device with a USB cable, open a terminal window and run the Android Debug Bridge (ADB) with these parameters to run logcat on the Android device and output only log messages from Unity:

adb logcat -s Unity
                    

To run adb from any folder on Windows, add the Android platform-tools folder to your PATH system variable. The path to the platform-tools folder will vary depending on where you installed the Android SDK, however it should be something like C:\Users\(YOUR WINDOWS USER NAME)\AppData\Local\Android\Sdk\platform-tools.

In your code, output messages and values of variables to help you debug using the Debug class like this:

Debug.Log("This is a debug message. The value of the name variable is " + name);
                    

Messages output by Debug.Log() will be tagged with an 'I' to indicate that it is an informational message. The Debug class also has methods for LogWarning() and LogError() that are tagged with 'W' and 'E' respectively. Output from logcat can be filtered further to only show the level of logging that you are interested in seeing.

With your device connected and adb logcat running, run the game on your phone and watch for log messages to appear in the terminal window.

Update: After writing this article I found a similar article in the Unity documentation.

Add Your Comment

Want to comment on this? Log in or Register to add your comments.