Installing Unity and linking a new project to GitHub
I’ll be using Unity for my game development efforts as it’s free for personal use*, more details can be found here. Let’s go ahead and get Unity installed so we can start having some fun, all while keeping our project files version controlled of course!😀
In my previous articles we’ve covered getting git installed and configured to use SSH for communicating with GitHub.
If you already have Unity installed, you can skip ahead to the Project Setup section.
There’s a few steps to this so let’s get right to it! First we need to head over to the Unity website to download the software. Once there click the “Get started”, this will open the “unity store” on a new page
- Click the “Individual” tab
- Under the Personal section click the “Get started” button
- In the Returning users section I’m going to click the “Go here” button
- I’m gong to accept the terms by checking the box
- After accepting the “Download Unity Hub” button should turn blue, click it and the download should start
Unity Hub is a handy app to manage your projects and unity installs. Once the download has completed open the file. You might be presented with a window asking to allow it to make changes to your device, to install confirm.
Following the steps through the installer you get the option to select where you want it installed. After the installation has completed you may get an alert from your firewall to enable Unity Hub access to the internet, I’ll allow it.
Once open it should look something like this:
- Even though Unity is free for personal use, we still need a license
- On the bottom a row has appeared telling us we have no valid license. Click “Manage License”
- The bar has now been replaced telling us to log in. Click “Log In”
- If you have a Unity ID already, enter your credentials and Sign in. If you don’t click the small link that says “create one” underneath the sub header.
- The license should get fetched after successfully logging in.
- We’re now ready to install a Unity Editor
The Unity Hub will by default install the Unity Editor(s) in
C:\Program Files\Unity\Hub\Editor, if you wish to change this to a different location all you have to do is click the small gear icon next in the top right of the unity hub. Clicking the three dots behind where it says “Unity Editors Path” will open up a file explorer allowing you to select the folder where you want it to install the editors, to save the new location hit “Save”. Hit the Left-arrow in the top left to go back to the main Hub interface.
Now we’re ready to get a Unity Editor installed 😁
The very left side of the hub gives you a menu to see the Unity Projects you’ve been working on, some learning materials/projects, a community tab with links to various unity content. And on the bottom we have “Installs”, this is where we’ll manage our editor installations, adding (or removing) editor versions and modules. After you’ve come to the installs section, hit the blue “Add” button to get started.
This will give you a short list of different versions to download, I would recommend, as Unity themselves do, to install the current LTS release (Unity 2020.3.0f1 as of this writing).
My suggestion is to have the Microsoft Visual Studio Community 2019 included as a minimum, unless you have it or a different editor you prefer already installed 🙂 The documentation is accessible online, so consider including it if you’re going to be working offline.
The installation might take a while, depending on your computer and internet speed. While it is installing, you’ll see it clearly indicated. Keep an eye on your computer as the Visual Studio 2019 installation might require your input to complete.
Once the installation is completed we’re now ready to create our first project!
Click “Projects” then on the blue “New” button. 3D should already be selected by default and give the project a name. This is also where you can change the location of where your project is store, once you’re satisfied click “Create”. This will create a new folder inside the location listed with the same name as the project. It’s important to note that it will not allow you to create a new project inside an already existing directory, the order of the steps here are of importance. So the project name must be unique in the location. This also influence the order of operation for connecting to a GitHub repository.
It might take a few moments for it to create the project, open up and be ready for us to use.
Open up PowerShell, and navigate to the Unity Project folder. I have mine at
C:\Users\Username\My First Project\, make sure to navigate into the actual project folder. Then type in
git init, this will initialize a repository on your computer, next let’s go to GitHub and create a new repository.
Enter a name for your repository (does not have to be the same as your Unity Project), and we’ll add a .gitignore.
A .gitignore file is there to tell git what files and folders it should ignore when you are adding and commiting things to the repo. This way things that such as caches and sensitive information can be excluded.
Since we’re working with unity click the field that just got enabled as you ticked the checkbox and type in “Unity”.
Hit “Create repository” and you will be taken to a new page showing your new repo. Clicking the green “Code” button will give you a dropdown where you can some information to connect the repo to your local project. Having SSH selected, click the clipboard button as indicated above, we need to use this in powershell:
git remote add origin+the text copied from your github repository. The structure should be like so:
git remote add origin firstname.lastname@example.org:githubusername/nameofrepo.git
You won’t get any feedback that it has been done except for it giving you a new blank line. To check you can enter
git remote -v.
If you’ve followed my previous articles both your local and remote branch is called “main”. We now need to pull down the data from GitHub down to your local repository, this because we want to get the .gitignore file before we start adding files into the our local repository. If we did that before having the .gitignore was present it would add everything, even the stuff we don’t want to upload.
In powershell run the command
git pull origin main, once that is completed you can double check the project folder on your computer to see it has magically appeared 😁
Now we can go ahead and add our project to our repo.
- First by running
git add ., this adds all (that’s the “.” ) the files that’s not set to be ignored, inot what is called a staging area. Depending on settings you might get a whole bunch of warnings about LF being replaced by CRLF. This is perfectly fine.
- Then we need to commit the changes by running
git commit -m "commit message". I’ll go ahead and run
git commit -m "created project"
- Home stretch, now we just need to push the changes to our github by running
git push origin main
That’s it your (empty) project is now online!
If you go back to your github repository and refresh you should now see some more folders have appeared.
Your project is now all set up for using git and properly linked to your github repsitory. Now when you have added features and files to your project, all you really need to do is:
- Add all new files to staging area:
git add .
- Commit your changes and give it a descriptor:
git commit -m "message"
- Push your changes online if you want to:
git push origin branchName
There is way more you can do with git, but that’s for another time.
Recap of steps to set up a new project with github repo:
- Create Unity Project
- Initialize local git repository
- Create GitHub repository with .gitignore
- Add github repository as remote
- Pull down the .gitignore
- Add files to staging area
- Commit changes
- Push to remote
Thank you so much for your time and attention, hope to see you again 😀