Search Unity

Linux: beginner's guide for developers :-)

Discussion in 'Getting Started' started by LinuxDevJ, Sep 27, 2020.

  1. LinuxDevJ

    LinuxDevJ

    Joined:
    Sep 26, 2020
    Posts:
    23
    I am a software developer without any game engine experience and started my very first Unity project. As I use a Linux distribution (Ubuntu 20.04 LTS) and just have experience in a Java IDE (Eclipse), I had just a rough idea how this could work. I was wrong. I searched various sources on the internet until I got my first project finally running, was able to built a Linux executable and finally setup debugging the C# code of Unity. So I had no experience with Unity, none with C#, and none with game development overall. It took me a whole day to finally had a small game with full development cycle. As this was all free, I wrote this guide to help other (non-)developers to get starting with game development with Unity (on Linux). :)

    1. Install Unity
    Well, this one is easy: go to the download page and click "Download Unity Hub". This will download a file "UnityHub.AppImage". I created a separate directory for this "Unity program" (e.g. "/Programs/Unity/"). As this is an "AppImage", there is no need to "install" this - you can simply run it. Of course, you first have to make the file "executable" if it is not already:

    > chmod a+x UnityHub.AppImage

    So just double click the file (or create a script with "./UnityHub.AppImage") and Unity will start. Be patient as some actions need some time to finish.

    The first time you start Unity, you will have to login with your Unity account (free) and "manage a license" by selecting the free "Personal" license.

    As UnityHub is just a thin container, you also have to install a Unity engine (called "Editor"). You need to install the specific Unity Engine(s) you like. But first go to preferences (icon top right) and set in "general" a "Unity Editors Folder" to avoid install them in your user's home directory. Then go to "Installs", click "ADD" and select the last LTS version (e.g. "Unity 2019.4.11f1 (LTS)"); click "NEXT" and wait some minutes until it's installed.

    Finished! You installed the UnityHub and the latest Unity LTS engine. You are ready to start developing games! The following example also describes the UnityHub basics. Time to get started:

    2. Write your first game
    Well, you have no idea where to start, right? :( But thanks to noobtuts, there are absolute beginner's tutorials. Select the "Pong Game" example and work through it. Don't think "I never write 2D games" :rolleyes:, just work through this tutorial - it is perfect for beginners as it describes everything needed from scratch: the basics of the Unity Editor and what to do step by step to write this simple game. I did that with the above managed Unity LTS engine and 99% of the descriptions were accurate - only a few settings were at different places (e.g. background color) due to the different Unity versions. For now, don't think about the standard text editor that pops up when you paste C# code. It took me about 3 hours to follow the instructions for thisPiong example, as I did this carefully and also looked into the Unity API and other ressources for better and further understanding. You could do this in probably 1 hour.

    In the end, you have a working pong game - horay! :D

    3. Setup a C# editor and debugger
    You noticed that the standard (Linux) editor pops up when you write C# scripts. Of course, this is not suitable for a developer as you also like to have syntax coloring, code highlighting, code completion, ... and the most important: debugging facility! :confused: I searched and tried multiple things I found on the net. E.g. multiple editors, but I finally decided to go for Visual Studio Code, because it seems to be the standard for Unity C# coding. :oops: I do not like Microsoft and its products but all the other editors I tried had some drawbacks - especially debugging. And VSCode is at least open source and works on Linux. ;)


    So, head over to the Visual Studio Code download page and download the ".deb" 64Bit Version. This will download a ".deb" file (e.g. "code_1.49.2-1600965325_amd64.deb"). Install this e.g. via

    > sudo dpkg -i code_1.49.2-1600965325_amd64.deb

    As a result VSCode is installed and can be started via "/usr/bin/code". In Unity (project), setup VSCode as your editor in

    Edit > Preferences > External Tools > External Script Editor

    by choosing "Browse..:" and type in /usr/bin/code - that's it! Whenever you open a C# script, VSCode is now started. :) As you open C# files (*.cs), VSCode will automatically offer to install the C# plugin - accept that. This will install C# facility in VSCode (syntax).

    And now the final, most important, most problematic feature: debugging! I tried a lot (e.g. VSCode.cs) but that never worked for me. :mad: Perhaps due to the fact that I am on Linux and not Windows. But what worked very easy and instantly was the "Debugger for Unity" plugin for VSCode:

    In VSCode, press CTRL+P, paste "ext install Unity.unity-debug" and let it finish install. :) Click the play/debug icon on the left pane and select "Unity Debugger" from the combo box. (If it does not appear, delete the file <myFirstProject>/.vscode/Launch.json. Restart VSCode and a new "Launch.json" will be created and "Unity Debugger" is selectable.)

    Finally, we debug our C# code: set a breakpoint in your main Unity C# script's Start() method in VSCode (as this method will be called in any case). Do not start the game in Unity yet! :eek: Start debugging in VSCode by clicking the green triangle in the debug view's selection box ("Unity Editor") => VSCode is now in "debug mode": icons appear to step in/over/out and stop, on the left side you see a "Call Stack". o_O So far, VSCode is just in debug mode and is listening for Unity ... next, we start in Unity our game via the standard "play" button ... tadaaaa! :) VSCode fill's its "Call Stack" and "Variables" and stop at the first breakpoint! From there, use your brain (or experience) to debug your code. :)

    Have fun! :cool:
     
    Last edited: Sep 27, 2020
  2. Deleted User

    Deleted User

    Guest

    Thanks a lot fam, you saved me nice couple of hours! ;)
     
  3. Magicono

    Magicono

    Joined:
    Apr 2, 2023
    Posts:
    1
    Thanks alot for the guide, LinuxDevJ. I was able to get VS-Code "attached" to the Unity Editor and accomplish most of the stuff I'd done on my Windows system before using Visual Studio. So I'm really thankful for your guide in getting me there, was really frustrated thinking I would have to go through hoops or be unable to atleast "freely" use VS-Code for my modding projects.

    The only thing I could not seem to get to work was the Unity Debugger "combo box" as you described. Which I assume means the extension added another tab to the top-left drop-down menus that gave the additional options you mentioned. Atleast I could not find on my system the "<myFirstProject>/.vscode/Launch.json" or anything resembling it as far as I searched atleast. (Hopefully I can get that resolved at some point.)

    But either way, thanks very much for atleast helping me get the most important basic aspects functional so I can hopefully continue my work.
     
  4. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Ah good lad! I tried to do my own version of Pong last week and failed horribly!