How to debug Unity Game in Editor Play Mode in Ubuntu 22.10

TL;DR version in first reply to this post. Long version ahead.

Hello! I’ve been fighting my way to get Unity working on a new Ubuntu 22.10 machine I recently repurposed for GNU/Linux. I got it to a point where the experience is quite similar to what I get from my other laptop (MacOS) when both use VSCode. I wanted to capture my process as I believe it can help others :smile:

First of all, to setup Unity in Ubuntu 22.04 LTS (the official distro supported by Unity) please follow the excellent post by Gennady: Unity Hub on Linux These instructions are apparently also applicable to 22.10. From this point on I managed to install a Unity version (2022.1.18f1) and open my project without a hitch. (Well, I had to #if-guard some of my code that was iOS specific, but for the rest that was it).

The final bit I needed in order to develop my game in Ubuntu was a way to attach a debugger and inspect the game state when hitting a breakpoint. Here are some steps I followed to get it working:

Step 1 - Install VS Code
I started by installing VS code. I tried both installing from the Ubuntu Software app (snap) and downloading the .deb file from the official page. Both approaches work the same for me.

Step 2 - Install the Unity Debugger extension
Once installed, I went to the extensions and downloaded the latest version of the extensions:

  • Debugger for Unity - this is not maintained anymore, but seems to keep working for now.
  • C# - this is a dependency for the debugger

8577571--1148872--upload_2022-11-10_20-5-14.png

At this point I tried to attach using CTRL+SHIFT+P and running the “Unity Attach Debugger” command. However I was getting “No Unity Process Found” pop-ups. Searching for this error I found the actual JS code used to attach calls “mono UnityDebugger.exe list”, so I tried to run that locally and found that “mono” was not a valid command :roll_eyes:

Step 3 - Install mono
I had to install mono by just typing:

sudo apt-get install mono-runtime
After the installation, I tried to attach the debugger from vscode again and I got a list of processes to attach to! Exciting! However, clicking on any process will just closed the menu, it’ll try to open the debugger panel, and it will close it almost immediately :frowning:

The key to solving this problem was looking at the logs for the extension. That file is on your home folder:
~/.vscode/extensions/unity.unity-debug-3.0.2/bin/UnityDebug-log.txt
My log had the following message:

20:06:25.365012: Log

20:06:25.370385: Unity Editor process: Unity on id: 4147
20:06:25.445041: UnityPlayerConnection is constructed
20:06:25.449719: Known size of available Players: 0
20:06:28.451626: New size of available Players: 0

Very cryptic - but made me think that my Unity player wasn’t ready to be debugged. Then I realised that you need to switch to “debug mode” in order to debug when playing in the editor.

Step 4 - Switch to Debug Mode
This one is very easy. Just hit the little “bug” icon on the bottom right of the Unity Editor. The official manual covers it very well: Unity - Manual: Debug C# code in Unity


I tried to attach after this and… nah, still wouldn’t work. I decided to check the log again in case it had changed. And it did indeed:

9:23:29.588527: Log

19:23:29.606478: UnityDebug
19:23:29.610110: Running session
19:23:29.616867: Exception: System.TypeLoadException: Could not load type of field ‘Mono.Debugging.Client.BreakpointStore:breakpoints’ (4) due to: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies.
at UnityDebug.Program.RunSession (System.IO.Stream inputStream, System.IO.Stream outputStream) [0x0000c] in <047db2e167724751817247551060301d>:0
at UnityDebug.Program.Main (System.String[ ] argv) [0x00048] in <047db2e167724751817247551060301d>:0

Clearly this is the UnityDebugger.exe (which is shipped with the Debugger for Unity vscode extension) trying to load an assembly (netstandard v2.0.0.0) that cannot find in the system. That led to me an issue in the mono github: Incorrect Debian package used for netstandard.dll · Issue #17148 · mono/mono · GitHub Apparently we have to install mono-devel to get this code library.

Step 5 - Install netstandard.dll via mono-devel
This is easy, just an apt-get command:

sudo apt-get install mono-devel
After all of this, finally, I managed to get vscode attached to Unity and breaking execution at my breakpoints!

I realise this post is quite long, but I’m very excited to get this working and wanted to share this in case it’s useful to anyone :slight_smile: I’ll write a quick summary of these steps in the first reply to this post.

1 Like

Quick summary:

  • Step 0 - Install Unity using the official guide: Unity Hub on Linux

  • Step 1 - Install vscode either via Ubuntu Software or by installing the official .deb package

  • Step 2 - Install both the deprecated “Debugger for Unity” and “C#” extensions for vscode.

  • Step 3 - Install mono: apt-get install mono-runtime

  • Step 4 - Switch Unity Editor to debug mode (click on bug-like icon on the bottom-right of the editor)

  • Step 5 - Install netstandard library: apt-get install mono-devel

  • Step 6 - Make Games! :sunglasses:

2 Likes

I found that also helps to call the debugger with ctrl+shift+P then select attach debugger and use the first unity instance that comes up