Make your first AR app | Unity

Sk Soyeb Akhter
5 min readJun 1, 2022

--

I don’t want to bore you by giving you lengthy definitions. Lets just start making the app.

Setting up the environment

  1. Install Unity Hub → link
  2. Open unity hub and install unity editor by going to “Installs” tab and then “Install Editor”. [I have already an editor installed. Don’t mind it.]

3. Choose a LTS version to install.

4. After choosing a version you’ll be prompted to add modules. Select accordingly. If you’re targeting android devices then add the android modules. If you’re also targeting iOS devices then also tick the iOS module options. In my case I will only go for android

5. Click “Continue” button then accept the agreement and then click on “Install” Button.

After the installation is completed, your system is ready for AR development.

Setting Up Project

  1. Open unity hub
  2. Go to “Projects” tab
  3. Click on “New project” button on the upper-right corner
  4. By default unity gives you some templates to choose from. In our case we will go with “AR” template. So select it.
  5. In the bottom right corner give your project a name. I have given it “MyFirstProject” and then select a destination folder.

6. Next click on the “Create project” button. It will take some moment to create your new project. After it unity hub will open your project automatically for you in the unity editor.

At this point you should see a window like this →

After it we will have to do a necessary step. From the menu bar go to Edit → Project Settings → XR Plug-in Management. Then go to “Android” tab and select the checkbox named “ARCore”.

Congratulations! With this your project is absolutely ready for building any AR app.

Building The AR App

Let’s build a basic AR app that will scan your surroundings and look for depth point.

Follow the steps :

  1. Click on : File → New Scene → Basic (Built-in)
  2. In the “Hierarchy” window delete the “Main Camera” by right clicking on it and then delete.

3. Add an AR session object by clicking : GameObject → XR →AR Session

4. Add an AR Session Origin object by selecting: GameObject → XR → AR Session Origin

5. Add a point cloud manager to the Session Origin object. To do this first click on “AR Session Origin”. Then go to the Inspector Window on the right hand side and click on “Add Component”. Search for “ar point cloud manager” and then select it.

You’ll notice that AR point cloud manager has an empty slot for Point Cloud Prefab, which is used for visualizing the detected depth points. Again if you’re new to this just follow along.

Create a particle system by selecting : GameObject → Effects → Particle System. In the inspector window rename it to ‘PointParticle’. Also uncheck the looping checkbox. Set its start size to 0.1

Uncheck the “play on awake” checkbox.

Click Add Component, enter “ar point” in the search field, and select “AR Point Cloud”.

Likewise, click Add Component and select “AR Point Cloud Visualizer”.

Drag the PointParticle object from the Hierarchy window to the Prefabs folder in the Project window (create the folder first if necessary by right clicking on the Project window → Create → Folder → name it ‘Prefabs’). This makes the GameObject into a prefab.

Delete the PointParticle object from the Hierarchy window using right-click → Delete or press the Del key.

The Inspector window of the PointParticle object should now look as follows

We can now apply the PointParticle prefab to the AR Point Cloud Manager, as follows:

  • In the Hierarchy window, select the AR Session Origin object.
  • From the Project window, drag the PointParticle prefab into the AR Point Cloud Manager → Point Cloud Prefab slot. (Alternatively, click the “doughnut” icon to the right of the slot to open the Select GameObject window, select the Assets tab, and choose PointParticle).
  • Save the scene by : File → Save → Go inside Scenes Folder → Name the scene ‘BasicScene’ → Save

Now we are ready to build and run the scene.

  • File → Build Settings → Choose Android → Switch Platform

Wait some moment, it will take time.

Next connect your android phone to your system via USB cable. And make sure that you have enabled USB debug in your android phone.

After it click the “Add Open Scenes” button on the “Build Settings” window.

Finally click on ‘Build and run” button.

Save the apk file as ‘FirstAR’.

If everything goes right then you will have a running app on your android phone thay looks like this →

This is a very basic AR app that scans your room and looks for depth points.

If you advance in your AR journey you will be able to make amazing apps and games with your knowledge.

If you want to get more stories related to development follow me. If you found any mistake in this article then please comment it. Bye. With love from India.

--

--

Sk Soyeb Akhter
Sk Soyeb Akhter

Written by Sk Soyeb Akhter

Indie Developer & Open Source Contributor

No responses yet