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 and use it as a base when building AR apps.
Download from Unity website
Download Unity from their website. You can either download a specific version of Unity or Unity Hub.
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.
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.
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.
I chose the version Unity 2020.3.24f1 (LTS), which was the recommended release during the time I was writing this blog post.
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, 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.
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.
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 is a platform that has tools for creating Augmented Reality applications. You will need an ARCore supported device for building Augmented Reality applications for Android. Many of the newer smartphones are capable of running AR apps.
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.
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.
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.
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.
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 if you are interested to see more about my days as a software developer and a gaming enthusiast!