Create an Augmented Reality (AR) Android App using Unity and Artoolkit


Tools Needed:
  1. Open Unity and click File/New Project

  2. Dialog-Box asking for Project Name, Location will open up. Write Project Name and set the location where you want to store your project and then click "Create Project"

  3. new Unity Project Window
  4. Uncompress Artoolkit library that you have downloaded and store it somewhere in your PC.

  5. Now, lets import Artoolkit library in Unity:

    • Select Assets/Import Package/Custom Package
    • Go to the location where you have uncompressed the Artoolkit library files
    • Select ARUnity5.unitypackage and click Open
    • Dialog-Box showing complete list of files in the ARtoolkit library would be shown. Select All Folders and click Import

  6. Create a new Scene:

    • Click File/New Scene
    • Save the scene by pressing CTRL+S and store it in projects root directory

    • Unity Scene

      Here, I have given my scene name as "Scene1" and clicked Save

  7. Delete "Main Camera" and "Directional Light" from "Scene1" Hierarchy tab displayed in left part of the screen

  8. Adding GameObject:

    • Select GameObject/Create Empty or press CTRL+SHIFT+N
    • Click on Gameobject in Hierarchy and goto inspector Tab and rename it to "Artoolkit" and hit Enter

    • Renaming Gameobject in Unity

    • Add another GameObject and Rename it to "Scene root"

    • renaming GameObject in Unity3d
    • Right click Scene root and add "Camera" and "Light/Directional Light" and "Create Empty" and rename Gameobject to "Marker"

    • Your Hierarchy tab should look like this:

      Unity Hierarchy tab

  9. Adding Scripts:

    • In Assets tab, Goto "ARToolKit5-Unity"/"Scripts"

    • Drag "ARController" and "ARMarker" from Assets to "Artoolkit" gameobject in Hierarchy tab

    • Dragging in Unity
    • In Hierarchy tab, click on "Artoolkit" option and at Inspector tab to the right, your tab should contain two scripts "ArController" and "ARMarker" as shown in image above.
    • Modify your ArController script setting as per image given below

    • Artoolkit AR Controller Setting
    • Follow above steps to Drag "AROrigin" from Assets tab to "Scene Root" gameobject in Hierarchy tab
    • Drag "ARCamera" from Assets tab to "Camera" gameobject to the left in Hierarchy tab
    • Drag "ARTrackedObject" from Assets to "Marker" gameobject in Hierarchy tab

  10. Adding Marker:

    We will be working with the markers already provided by ARtoolkit library. If you want to create your own marker read this article Create Custom Marker

    • Marker that I have used is

    • Hiro Marker
    • In Hierarchy tab, select "ARtoolkit" option and in Inspector tab goto "ARmarker" Script, give your marker tag an unique name which you can easily remember and use it again. In below image, I have named my Marker tag as "marker1"

    • Naming Marker Artoolkit Unity
    • Select "Marker" from Hierarchy and in inspector tab goto "AR Tracked Object" Script, give Marker tag same name as you have given above. In my case, I will name it as "marker1"
    • As soon as you type "marker1" in your marker tag textbox, you can see "Got Marker" status changes to "Yes". If not, follow above steps to check whether your script is added properly and make sure marker tag name in "ARMarker" and "AR Tracked Object" is same

    If you have created a custom marker, put the pattern file in "Assets/ARToolKit5-Unity/Resources/ardata/markers" location. And in ARToolkit script and ARMarker script change the pattern file name to what you have inserted in "Assets/ARToolKit5-Unity/Resources/ardata/markers" location.
    Adding your Own Marker

  11. Adding Object that you want to display on Augmentation:

    • I am adding a Simple 3D "sphere" you can add anything you want like cube, capsule or any animation.
    • To add "Sphere" object, right click "Marker" and Select "3D Object"/"Sphere"
    • Scale the Sphere object to make it visible on display screen.Set your transform values to one I have set in below image

    • Scaling Gameobject in Unity

  12. Adding Layers:

    • Click on "ARToolkit". By default Layer is set to "Default". From DropDown List select "Add Layer". Add two layers "AR Background" and "AR Foreground" as shown in below figure.
    • Layer in Unity
    • In "Scene root", change layer to "AR Foreground". Be sure to change all its children?s layer to 'AR foreground' as well (click the button 'yes, change children').

    • Change Artoolkit ArController Layer
    • In "Camera", change Culling Mask to "AR Foreground"

    • Artoolkit cullingMask

  13. Our App is already ready, Now lets deploy it on Android

    • Plug in your Android Mobile to PC
    • Click on File/Build Settings/Add Open Scenes. You should see something like this.

    • Unity build Setting Artoolkit
    • Look here to change your settings to export your application to Android Mobile
    • Just Click on Build and Run. You would be asked to Enter the name and set the location for apk file. Give the app an appropriate name and location and click "save"
    • Wait For some time and your app would start on your device.

  14. When your App starts you could see the camera of your device starts, just point your device towards the marker you have used. You should see something like this on your device.

    Augmented View
  15. If you have any doubt or suggestion, please comment below. That would help you as well as others who read this post.


Solution Didn't Worked 2 DownvotesDownvote