Unity with VsCode in Linux (Fedora 38)

Unity with VsCode in Linux (Fedora 38)

Greetings

Hello, fellas. I recently swapped to a new Linux distro, Fedora 38, and I found out that making Unity work properly there is not a 5-minute task. There is no complete tutorial for that, so I decided to make one.

I recommend Ubuntu 22.04 LTS more, that Fedora, for users with weak PCs, because of performance. This tutorial is still valid for Ubuntu (if you use setup for weak PC), just change "dnf" to "apt-get" and install dotnet sdk 6 instead of 7.

Let's go ahead and get started!?


Table of content

  1. System update
  2. UnityHub installation
  3. Unity installation and possible problems
  4. VsCode installation and setup for powerful PCs
  5. VsCode setup for weak PCs
  6. Performance improfements


System update

First, before installing anything, update your system. This can take some time if it was recently installed. Type the following in your terminal and press Enter:?

sudo dnf update        

UnityHub installation (credit)

There is the first potential issue. One might be tempted to open the " Software " application and download Unity Hub from there, but this is a suboptimal solution, because:?

  • it will download a lower unofficial UnityHub version than is currently available;
  • the downloaded application will only be able to see the "Software" VsCode version, which is also unofficial and lacks the built-in terminal, which is considered a defect.?

The correct method is to use the terminal again. Acclimate yourself to it if you have not yet; it will be used throughout this tutorial and also in Linux in general.?

The next command to copy-paste adds UnityHub to the repository:

sudo sh -c 'echo -e "[unityhub]\nname=Unity Hub\nbaseurl=https://hub.unity3d.com/linux/repos/rpm/stable\nenabled=1\ngpgcheck=1\ngpgkey=https://hub.unity3d.com/linux/repos/rpm/stable/repodata/repomd.xml.key\nrepo_gpgcheck=1" > /etc/yum.repos.d/unityhub.repo'        

And following updates cache and installs (if this not working, try to change "dnf" to "yum"):

sudo dnf check-update
sudo dnf install unityhub        

After that you should be able to open it with unityhub terminal command. Or simply access it through Fedora application menu.


Unity


Installation

Open up UnityHub and after you sign-in you should see an installation window. Which looks like that, but with a Linux installation path.

No alt text provided for this image

You can click the "Install Unity Editor" button to install the last LTS version, but you can also skip the installation and install a different version by?

  • either skipping the installation by pressing the "Skip installation" button, entering the "Installs" tab, pressing "Install Editor", and clicking on one of the offered versions.?
  • or by opening Unity's download archive, selecting a version, and pressing the "UnityHub" button to continue downloading in UnityHub.?

I prefer the last option.?


Problems

If you whenever face the "There is not enough space to download and install the selected items" problem during the installation, which I did, open your terminal and make a "tmp" directory in your main user folder (home folder).

mkdir ~/tmp        

Then, in UnityHub, open Preferences -> Installs and change the Download location to just created folder. In my case, it looks like this.

No alt text provided for this image

VsCode


Installation (credit)

As mentioned earlier, VsCode from "Software" is not our choice. To install it properly, type in the terminal following to install the VsCode key and repo:

sudo rpm --import https://packages.microsoft.com/keys/microsoft.as
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'c        

And this will update package cache install VsCode itself.

dnf check-update
sudo dnf install code        

Get started

Create a new Unity project and open it. Next, open up?Unity Preferences ->?External Tools, then select Visual Studio Code as?External Script Editor.

No alt text provided for this image
credit: https://code.visualstudio.com/docs/other/unity

You also need to install dotnet SDK, so write this command to you terminal:

sudo dnf install dotnet-sdk-7.0        

Set-up for powerful PCs

It's quite simple:

  • Create a new Unity project and open it
  • Open Package Manager and make sure that the?"Visual Studio Editor"?package is upgraded to?2.0.20?or above

No alt text provided for this image
credit: https://code.visualstudio.com/docs/other/unity

  • Install the Unity VsCode extension; it will install the C # and C # Dev Kit extensions as dependencies. If these extensions do not install, install them yourself. Ensure that all your extensions are up to date.?


Set-up for weak PCs

  • Download mono (there are some extra packages, to download less, change "complete" to "devel"):

sudo apt-get install mono-complete        

  • Install C# extension (1.24.0). To do this, just install the C# extension -> click on the arrow right to "Uninstall" to view options -> hit install another version -> choose 1.24.0
  • Hit Ctrl + ` to open settings, search for Omnisharp:?Use Modern Net and uncheck it. Now go to the "If auto-completion does not work" section of this tutorial. If it didn't help, complete the next step.
  • Search for Omnisharp: Use Global Mono and set to always -> type Omnisharp:?Mono Path and set it to your mono path (/usr/bin/mono in my case). You can check what is your path by typing "whereis mono" in your terminal.

If auto-completion does not work

  1. Try to reopen VsCode by clicking Open C# project in Unity
  2. Try to restart Omnisharp by Ctrl + Shift + P and searching for Restart OmniSharp
  3. Try to restart the PC and return to steps 1 and 2
  4. Read Omnisharp logs and search for errors on the internet

Note: give step time to take effect, don't go to the next step immediately.

Performance improfements

It is important to make programs less demanding for weak PCs. Fortunately, Linux has a "nice" command to address this issue. This command helps to prioritize programs by setting their niceness.

To launch Google Chrome, type?

nice -n 15 google-chrome        

To launch Unity, type the command below, and then select the folder containing your Unity project.?

nice -n 13 /home/<YOUR USER NAME>/Unity/Hub/Editor/<YOUR UNITY VERSION>/Editor/Unity        

Change words in <> to something sensible in your case. That path may be slightly different depending on the Unity file location.?

You can obtain additional information about the nice command by entering it into the terminal command below.?

man nice        

I use the exact same values after- n when I work with Unity and Google in conjunction.?

要查看或添加评论,请登录

社区洞察

其他会员也浏览了