Getting started in ARcore for Android in Unity

In this article, I will explain how to get started with AR development using ARcore and Unity.

To get started Unity does make it pretty easy. You can download the AR template and Unity will set most of the environment up for you.

There are a few things to change in order to have the environment set up correctly.

The first step is to switch over to the Android environment once your project has loaded. You can do this by going to “File” > “Build Settings ”, selecting “Android” > then “Switch Platform”.

Once Unity has compiled we can adjust our Player settings to enable and support ARCore. The build window should still be open, click “Player Settings” > “Player” > “Other Settings” and click the Android icon.

We need to ensure “Auto Graphics API” is unchecked and if “Vulkan” is listed under the “Graphics APIs” settings it needs to be removed as ARCore does not yet contain support for it.

We now need to provide a package name under the “Identification settings. I’m just going to add a generic one as an example “com.example.ARExample”.

The next step is to select the minimum API level. For apps that require AR select “Android 7.0 ‘Nougat’ (API Level 24)”. If your app will have an optional AR component select “Android 4.0 ‘Ice Cream Sandwich’ (API Level 14)” or higher.

In the “Configuration settings” set the Scripting Backend to “IL2CPP”, and check the “ARM 64” checkbox under Target Architectures. This is to cover Google play requirements for 64-bit devices. You can read about this on the Google Developers website.

The next step is to enable ARCore in the project settings. With the Project Settings window still open select “XR Plug-In Management”, switch to the Android tab and under the Plug-In Providers check the “ARCore” checkbox.

We now want to ensure the AR packages are installed in our project. Go to “Window” > “Package Manager” and switch the filter over to “Unity Registry”. “AR Foundation”, “ARKit XR Plugin”, “ARCore XR Plugin”, “Magic Leap XR Plugin”, “ARKit Face Tracking”, and “OpenXR Plugin” should all be installed/locked if you created your project from an AR template from Unity Hub.

We now need to add in the Univeral Render Pipeline from the Package Manager. Find “Universal RP” on the list and click the “Install” button.

Once this has been installed we need to create a “Universal Render Pipeline Asset” by right-clicking in our Project tab, in the assets folder and selecting “Create” > “URP Asset (with Univeral Renderer)”.

This creates “New Universal Render Pipeline Asset” and “New Universal Render Pipeline Asset_Renderer”.

On the “New Universal Render Pipeline Asset_Renderer” object we want to click on the “Add Renderer Feature” button and select “AR Background Renderer Feature”

In our hierarchy we need the following objects “AR Session Origin” “AR Camera” (this will be a child of the AR Session Origin object), an AR Session and a Directional Light, I will expand on their components in my next article.

Finally, we just need to switch over our AR Camera so it is tagged as the main camera.

From this point, the AR environment should be ready to go. If you build and run to your device your phone should receive a video feed and even can see the plane textures start to render on flat surfaces.

For my future examples, I will only be working on horizontal surfaces so I will switch over to this setting. I did this by selecting the AR Session Origin object, and under the “AR Plane Manager” component, I changed the detection mode from “Everything” to “Horizontal”.

That’s all for now.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Luke Duckett

Luke Duckett

Unity developer with a love of learning all things programming.