Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code won't launch from within Unity #41

Open
ChrisTucker2000 opened this issue Jun 23, 2020 · 13 comments
Open

VS Code won't launch from within Unity #41

ChrisTucker2000 opened this issue Jun 23, 2020 · 13 comments

Comments

@ChrisTucker2000
Copy link

I'm trying to get Unity to work alongside VS Code, with both installed as Flatpaks. As far as I can tell, this Flatpak is supposed to have support for this, as there's a vscode.py file in the repository talking about launching the Flatpak and bridging together the sandboxes. Sounds great... but it isn't working for me.

I have a Unity project with vscode-editor set as the external code editor, with $(File) set as the args. This is how it was configured out of the box. The first time I tried to open a script from within Unity, it told me to install the .NET and Mono extensions. I installed them from GNOME Software, and running flatpak list -a confirms that I have org.freedesktop.Sdk.Extension.dotnet and org.freedesktop.Sdk.Extension.mono5 installed. (Note: I also have com.visualstudio.code.oss and com.visualstudio.code installed — I already had those in the first place.)

After installing the extensions, I tried again to open my script from within Unity... and nothing happens. I've tried restarting Unity, but it's still the same thing. Nothing happens. Looking at GNOME Logs, I can see the messages Started flatpak-com.visualstudio.code.oss-92753.scope. and flatpak-com.visualstudio.code.oss-92753.scope: Succeeded. appearing when I try to open the script, but nothing else shows up in the log and VS Code doesn't open. If I run Unity through the terminal, there's no error output or anything. If I open System Monitor, I can see that there's no VS Code process running in the background.

Nothing happens.

I've tried hacking around to find my own solution, but I can't get anything that I'm happy with. If I set flatpak-spawn as the editor, and set its arguments to --host flatpak run com.visualstudio.code.oss $(File), then I can open my files in VS Code through Unity. However, it only opens single files (no folder/solution), and every time I open a file it launches an entirely new instance of VS Code, which isn't ideal...

Any advice? Thanks.

@refi64
Copy link
Collaborator

refi64 commented Jul 6, 2020 via email

@PureTryOut
Copy link

Is there any progress on this? For me Unity just gives me a popup saying I need to install Visual Studio Code, even though I already have it installed as a Flatpak. Right now I just open Visual Studio Code manually and select the "Open Folder" option to then select the Unity project.
It would however be much nicer if I could just double-click a script from within Unity itself...

@djotaku
Copy link

djotaku commented Jan 23, 2021

What distro are you on? It works for me on Fedora 32. Both VS Code and Unity installed as flatpaks.

@PureTryOut
Copy link

Alpine Linux, but I'm not sure why that would matter. I thought the whole point of Flatpak was to not have to care about the base system anymore.

@refi64
Copy link
Collaborator

refi64 commented Jan 25, 2021

Oof I had thought this had been fixed in one of a61ceaf or fae935f, but I guess it wasn't... I can't reproduce it, but I'm also on Fedora as well, so I might have to spin up an Alpine VM at some point and see.

I thought the whole point of Flatpak was to not have to care about the base system anymore.

Technically yes, but for this Flatpak we do shell out to the base system to run the VSCode Flatpak to work around some hardcoded Unity stuff.

@Yabgu
Copy link

Yabgu commented May 11, 2022

It does not work because it is trying to search the "dotnet" with runtime 21.08 which is not available now: flathub/org.freedesktop.Sdk.Extension.dotnet#14

To overcome this I installed dotnet6//21.08 and edited the file installed in the system "/var/lib/flatpak/app/com.unity.UnityHub/x86_64/stable/e5bea653114a7a097b2be5320a667fabc1eb9ff0b49d120e61b318ec0d2f075c/files/bin/code" (vscode.py) as in the following:

  • I commented the messagebox dialogbox warning
  • changed every "dotnet" to "dotnet6"
  • Installed mono6 and dotnet6 for 21.08

It is working now. I think it is safe to switch to dotnet6 for now.

And for IntelliSense to work there is another issue we need to fix with the mono6 script: Mono6 enable script unlike dotnet6 enable script, is using a variable for some reason. This variable for good reasons is not set in the unity hub environment so it doesn't set the environments correctly; Quoting the current script "/usr/lib/sdk/mono6/use.sh" below:

export PATH=$PATH:${FLATPAK_DEST}/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${FLATPAK_DEST}/lib
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}${FLATPAK_DEST}/lib/pkgconfig
export MONO_GAC_PREFIX=/app

To fix it we can set FLATPAK_DEST before calling it.

I am attaching the diff for my workaround for the file https://github.com/flathub/com.unity.UnityHub/blob/master/vscode.py below

--- /home/acakar/vscode.py
+++ /home/acakar/vscodefix.py
@@ -60,10 +60,10 @@
 
 for (( i=$$; i < $target_pid; i++ )); do /usr/bin/true; done
 /tmp/Unity infinity &
-
-[[ -d /usr/lib/sdk/dotnet ]] && . /usr/lib/sdk/dotnet/enable.sh
+[[ -d /usr/lib/sdk/dotnet6 ]] && . /usr/lib/sdk/dotnet6/enable.sh
+FLATPAK_DEST=/usr/lib/sdk/mono6
 [[ -d /usr/lib/sdk/mono6 ]] && . /usr/lib/sdk/mono6/use.sh
-
+unset FLATPAK_DEST
 # Note: don't do grep -q, code --list-extensions doesn't like SIGPIPE
 if $code --list-extensions | grep ms-vscode.csharp >/dev/null &&
   ! grep -qs '"omnisharp\.useGlobalMono"\s*:\s*"never"' \
@@ -232,11 +232,11 @@
         else:
             ref_to_search = missing_sdk_extension_refs[0]
 
-        await not_installed(ref=ref_to_search,
-                            title='dotnet and mono6 SDK extensions are required',
-                            text='The dotnet and mono6 SDK extensions are required for the Unity '
-                                 'debugger to work.',
-                            branch=sdk_arch_branch.split('/')[-1], available_on_web=False)
+        #await not_installed(ref=ref_to_search,
+        #                    title='dotnet and mono6 SDK extensions are required',
+        #                    text='The dotnet and mono6 SDK extensions are required for the Unity '
+        #                         'debugger to work.',
+        #                    branch=sdk_arch_branch.split('/')[-1], available_on_web=False)
 
     target_pid, transport = await forward_unity_socket(unity_port)
     res = await flatpak('run', '--command=bash', ref, '-c', VSCODE_SCRIPT, '--', str(target_pid),

After all these, you need to be sure VSCode setting "omnisharp.useGlobalMono" is set to "always". After all these it is now working including intellisense,

@refi64
Copy link
Collaborator

refi64 commented May 15, 2022

@Yabgu please try #68 and see if it works for you

@Yabgu
Copy link

Yabgu commented May 16, 2022

@refi64 it works. I just needed to install dotnet5 and mono6 for 21.08 target. We can call this is fixed with that PR,

@taranasus
Copy link

taranasus commented Jan 5, 2023

Hi, just wanted to mention that this appears to be broken again.

After installing the latest version of UnityHub that checks for dotnet5 instead of dotnet there are a few issues now that present themselves.

First off, the error message was not updated to reflect the need for "dotnet5" instead of "dotnet" which made it very confusing when trying to t-shoot the problem as I already had dotnet installed and was still getting the error message.

image

Second, at least in my case, the script is looking for the 22.08 version of the sdk packages and not 21.08, which makes the whole thing not work with dotnet5 as that stops at 21.08. I've modified the alert message that the script generates to figure this out.

image

I'd recommend modifying the error message to the following so that it's more descriptive to the user:

await not_installed(ref=ref_to_search,
                            title='Missing SDK extensions are required',
                            text='The following SDK extensions are required for the Unity debugger to work \n\n'
                                 f'org.freedesktop.Sdk.Extension.dotnet6/{sdk_arch_branch}\n'
                                 f'org.freedesktop.Sdk.Extension.mono6/{sdk_arch_branch}\n',
                            branch=sdk_arch_branch.split('/')[-1], available_on_web=False)

image

So I've modified the file further to look for dotnet6 instead of dotnet5 and installed the appropriate dotnet6 packages. Now my final problem is that when I click a .cs file in Unity, even though the error message no longer shows up as all validation passes, VS Code does not start just like @ChrisTucker2000 reported initially. If I start VS Code manually and point it at the project folder everything works just fine.

Any advice would be greatly appreciated.

@FullStackFlamingo
Copy link

As you've highlighted @taranasus , things have moved on, and we are force to move to 22.08 branches, dotnet6 rather than 5, and on top of that the omnisharp vscode extension requires the full mono6 with msbuild (something that is unfortunately missing in the flathub mono6 release!).

But luckily @priahoud has recently done the work to progress on these:

  1. correct dotnet6 + omnisharp usage in UnityHub : Fix code editor checks and settings #82
  2. mono6 to include msbuild : Add msbuild utility org.freedesktop.Sdk.Extension.mono6#13
  3. @FakeShemp with the 22.08 update Update runtime to 22.08 #73

@camperotactico
Copy link

I am facing a similar issue. I am using UnityHub and VSCodium (both from flatpak) on Fedora 39.
I am quite a newbie with flatpaks overall so I followed a this guide installing both mono6 and dotnet6 versions 23.08 to get VSCodium to open my Unity3D projects without issues and intellisense working.

However, I am not able to open VSCodium through Unity3D. Since I had a similar issue when working with MacOS in the past, I created a bash/zsh alias "code" that just runs the flatpak version of codium and made sure it worked fine on my host system.

Unity3D still refused to open any files, nor the C# repository. I also tried creating a "fake" Visual Studio Code app that is just a script containing:

!/usr/bin/zsh
flatpak run com.vscodium.codium $@

And then I configured the Unity3D editor like so with no luck:
Screenshot from 2023-12-03 02-30-41

I feel like am so close to get it working together, but I am making a rookie mistake somewhere along the way. Does anyone know what am I doing wrong?

@taranasus
Copy link

taranasus commented Dec 3, 2023 via email

@camperotactico
Copy link

Hi,

How could I make sure UnityHub and VSCodium have the proper permissions set to interact with each other? I have flatseal installed, but I am not sure how to setup what is suggested in your response.

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants