Unity setup and ARCore installation
Tags: beginners, tutorial, unity3d, android
Published: 2022-01-04 12:57:05

This step-by-step guide is meant as a starting point when building Augmented Reality applications with Unity! You can also download this project from my [Github](https://github.com/whatminjacodes/tech-tuesday-tutorials/tree/main/intro-to-ar/01-arcore-and-unity-setup) and use it as a base when building AR apps.

## Download from Unity website
Download Unity from their [website](https://unity3d.com/get-unity/download). You can either download a specific version of Unity or Unity Hub.

[Unity Hub](https://unity.com/unity-hub) is a management tool that allows multiple Unity version installations and it has good tutorials to get started with the development.

I chose Unity Hub version 2.4.5.

## Run the installer
After running the installer and opening Unity Hub it will ask you to activate a licence. 

![Unity Hub asking to activate a licence](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h307ekrpxh1f4ac354a2.jpg)

You will need a payed version of the software if you work in an enterprice that gets over $100000 in revenue. For personal use it is free.

## Getting a licence
If you don't have an UnityID, create it on Unity website. After that you can sign in to Unity Hub and activate a new licence.

![Activating Unity licence](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6oyn3vacwx6ri250mitk.jpg)

Using Unity is free for personal use.

## Adding Unity installations
After activating the licence you can add Unity installations. Go to Installs on Unity Hub and click Add.

![Adding Unity installation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dgj214fsg0nj8471mh7e.jpg)

I chose the version Unity 2020.3.24f1 (LTS), which was the recommended release during the time I was writing this blog post.

![Adding Unity packages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjhqr4zyg9cmiggg0jdl.jpg)

I recommend also downloading Visual Studio Community. It's free to use for personal and Open Source projects. You also need Android SDK & NDK Tools and OpenJDK to be able to build for Android.

You can also download [Visual Studio Code](https://code.visualstudio.com/), which is an open source code editor, if you prefer that.

## Creating a project
After waiting for Unity to install (it might take a long time) we are finally able to create our first project.

![Screenshot of project creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kae2q03kyueiwmilp9ja.jpg)

Choose 3D, give the project a name and choose a location to save. Click Create and wait for the project to open (this might take some time too).

## Testing Android build
You have to enable developer options on your phone before you are able to build to it. It's done a bit differently on each Android phone so you need to search how to do it with your phone.

![Developer options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zgv60zcm7egvzuk1ahes.jpg)

I have Samsung Galaxy Flip 3 and the developer options are enabled by going to Settings --> About phone --> Software information and repeatedly tapping on Build number. Then go to the Developer options and enable USB debugging.

Go to File --> Build Settings on Unity and click Add Open Scenes to add the current scene to the build. Then change the platform to Android and click Switch platform. It will take some time but this will change the build so it can be installed on Android.

After the platform has been switched, click Player Settings on the same Build Settings window that we were on before. Add a Company Name (just some unique name that you can use, I put whatminjacodes) and and Product name (I put intro-to-ar-part-1).

After that you can connect your phone to your computer using a cable. Make sure your phone is on USB for file transfer mode. Your phone might ask for permission to build over USB and you need to allow it for this to work. Then click Build and Run and choose where to save the build on your computer. After that the Unity app should open on your phone when the build is done. 

## Downloading ARCore
[Google ARCore](https://developers.google.com/ar) is a platform that has tools for creating Augmented Reality applications. You will need an [ARCore supported device](https://developers.google.com/ar/devices) for building Augmented Reality applications for Android. Many of the newer smartphones are capable of running AR apps.

![Unity's package manager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5e38jtufr3zy41s74jup.jpg)

Open Window --> Package Manager in Unity and search for ARCore XR Plugin. Remember to switch the search to include everything (Packages: Unity Registry on top left) and click Install.

Then search for AR Foundation and install that too.

![XR Plug-in Management](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/za9xfar9ki5kxny7fbn5.jpg)

Next go to Edit --> Project settings, open XR Plug-in Management and enable ARCore.

## Configure ARCore

Next we can delete everything except Directional Light from the scene Hierarchy. Right click on Hierarchy, choose XR and add ARSession and ARSession Origin to the scene.

![Adding ARSession to the Unity Hierarchy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ksgfq1acdbovgdj21aqo.jpg)

ARSession controls the lifecycle of an AR experience and ARSession Origin transforms AR coordinates into Unity world coordinates.

Lastly, go to File --> Build settings and open Player settings. Apply these changes:
- Other settings --> Rendering: Uncheck Auto Graphics API. If Vulkan is listed under Graphics APIs, remove it as Vulkan is not yet supported by ARCore.
- Other settings --> Minimum API level: If you are building an AR Required app, specify Android 7.0 'Nougat' (API Level 24) or higher. If you are building an AR Optional app, specify Android API Level 14 or higher. (We are building an AR required app)
- Other settings --> Scripting Backend: Select IL2CPP instead of Mono to allow ARM64 support to be enabled in the next step.
- Other settings --> Target Architectures: To meet the Google Play 64-bit requirement, enable ARM64 (64-bit ARM). Leave ARMv7 (32-bit ARM) enabled to support 32-bit devices. 

All of these settings are listed on [ARCore documentation](https://developers.google.com/ar/develop/unity-arf/getting-started-ar-foundation).

## Summary
This was a long step-by-step guide on how to install Unity Game Engine and Google ARCore plugin! You can use this as a base whenever you start building new AR apps on Unity. You can also download this starting project from my [Github](https://github.com/whatminjacodes/tech-tuesday-tutorials/tree/main/intro-to-ar/01-arcore-and-unity-setup).

Next week I'll publish a tutorial on how to do a simple AR application!

Give me a follow if you want to see more tutorials! You can also follow my Instagram [whatminjaplays](https://www.instagram.com/whatminjaplays/) if you are interested to see more about my days as a software developer and a gaming enthusiast!