Hey there! I’m part of a Unity supplier team, and today I’m stoked to share with you how to use the Unity AR Foundation. It’s a really cool tool that’s been making waves in the augmented reality (AR) world, and I’m gonna break down how you can get the most out of it. Unity

Getting Started with Unity AR Foundation
First things first, if you’re looking to dive into the world of AR using Unity, you gotta understand what AR Foundation is. In simple terms, AR Foundation is a plugin for Unity that gives developers a way to create AR experiences across different platforms. It’s like a bridge that connects Unity – a well – known game development platform – with the AR capabilities of various devices.
To start using AR Foundation, you need to have Unity installed on your machine. Head over to the official Unity website and grab the latest version. Once you’ve got Unity up and running, you can install the AR Foundation package. In the Unity Editor, go to Window > Package Manager. Here, you’ll see a list of available packages. Find the AR Foundation package and hit the Install button.
After the install is complete, you’re ready to start creating your first AR project. Create a new project in Unity, and you’ll notice that AR Foundation has added some new options and components for you to work with.
Setting Up the AR Scene
Once you’ve got AR Foundation installed in your project, it’s time to set up your AR scene. The first step is to add an AR Session Origin and an AR Session to your scene. The AR Session Origin is like the anchor point for all your AR content. It’s responsible for managing the position and scale of your virtual objects in the real – world space. The AR Session, on the other hand, is what initializes and manages the AR experience on the device.
To add these components, right – click in the Hierarchy panel in the Unity Editor and go to XR > AR Session Origin and XR > AR Session. You’ll see these two new objects added to your scene.
Now, let’s talk about tracking. AR Foundation supports different types of tracking, like plane tracking, image tracking, and face tracking. If you’re interested in creating an AR experience where virtual objects can be placed on real – world surfaces, you’ll want to use plane tracking.
To enable plane tracking, you need to add an AR Plane Manager to your AR Session Origin. You can do this by clicking on the AR Session Origin in the Hierarchy panel, then in the Inspector panel, click Add Component and search for AR Plane Manager. Once added, the AR Plane Manager will start detecting horizontal and vertical planes in the real – world environment as soon as the AR experience is launched on a device.
Creating and Placing AR Objects
Okay, so you’ve set up your AR scene and enabled plane tracking. Now it’s time to create some virtual objects and place them in the real – world space.
Let’s say you want to create a simple cube as your AR object. In the Unity Editor, right – click in the Hierarchy panel and go to 3D Object > Cube. You’ll see a cube added to your scene. You can customize the cube by changing its color, size, and other properties in the Inspector panel.
To place this cube on a detected plane, you’ll need to write a bit of code. Don’t worry if you’re not a coding expert; Unity makes it relatively easy. Create a new C# script in the Unity Editor by going to Assets > Create > C# Script. Name it something like PlaceCubeOnPlane.
Open the script in your preferred code editor. Here’s the basic code you can use to place the cube on a detected plane:
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using System.Collections.Generic;
public class PlaceCubeOnPlane : MonoBehaviour
{
public ARRaycastManager raycastManager;
public GameObject cubePrefab;
private GameObject placedCube;
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
if (raycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
{
Pose hitPose = hits[0].pose;
if (placedCube == null)
{
placedCube = Instantiate(cubePrefab, hitPose.position, hitPose.rotation);
}
else
{
placedCube.transform.position = hitPose.position;
placedCube.transform.rotation = hitPose.rotation;
}
}
}
}
}
}
In this code, we’re using the ARRaycastManager to detect when the user touches the screen. If the touch hits a detected plane, we either create a new cube or move the existing one to the hit position.
Back in the Unity Editor, attach this script to an empty GameObject in your scene. Then, in the Inspector panel of that GameObject, assign the ARRaycastManager (it’s attached to the AR Session Origin) and the cube you created earlier as the cubePrefab.
Using AR Foundation for Different Tracking Modes
As I mentioned earlier, AR Foundation supports various tracking modes. Let’s take a quick look at image tracking.
Image tracking allows you to detect specific 2D images in the real – world and place virtual content on top of them. To use image tracking, you need to create an Image Library. In the Unity Editor, go to Assets > Create > XR > AR Reference Image Library.
After creating the library, you can add images to it. These images are what your AR app will look for in the real – world. To add an image, click on the + button in the Image Library inspector and select an image file from your computer.
Next, add an AR Image Manager to your AR Session Origin. In the Reference Image Library field of the AR Image Manager, select the Image Library you just created.
Now, you can create a prefab that you want to appear when the image is detected. Similar to the cube example, you can write a script to handle the appearance of the prefab. Here’s a simple script:
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class ImageTrackingHandler : MonoBehaviour
{
public ARTrackedImageManager imageManager;
public GameObject prefabToSpawn;
private void OnEnable()
{
imageManager.trackedImagesChanged += OnTrackedImagesChanged;
}
private void OnDisable()
{
imageManager.trackedImagesChanged -= OnTrackedImagesChanged;
}
void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
foreach (var trackedImage in eventArgs.added)
{
Instantiate(prefabToSpawn, trackedImage.transform.position, trackedImage.transform.rotation);
}
}
}
Attach this script to an empty GameObject, assign the AR Image Manager and the prefab you want to spawn, and you’re good to go.
Testing Your AR Project
Once you’ve created your AR project, you’ll want to test it on a real device. AR Foundation supports multiple platforms, including Android and iOS.
If you’re targeting Android, make sure you have the Android SDK and NDK installed and configured in Unity. Go to Edit > Preferences > External Tools and set up the paths to the Android SDK and NDK.
To build and run your project on an Android device, connect your device to your computer via USB and enable USB debugging on your device. Then, in the Unity Editor, go to File > Build Settings. Select Android as the platform and click Build And Run.
For iOS, you’ll need a Mac with Xcode installed. In the Build Settings, select iOS as the platform. You’ll also need to set up your Apple Developer account in Unity. After that, hit Build. Unity will generate an Xcode project. Open the Xcode project and run it on your iOS device.
Why Choose Our Unity – Related Services
At our Unity supplier team, we’ve got a ton of experience working with Unity and AR Foundation. We know all the ins and outs of creating amazing AR experiences. Whether you’re a startup looking to launch your first AR app or an established company wanting to enhance your existing products with AR, we can help.
We offer custom development services. If you have a unique idea for an AR project, our team of developers can bring it to life. We’ll work closely with you from the planning stage to the final deployment.

We also provide support and maintenance services. Once your AR app is up and running, we can make sure it stays bug – free and up – to – date with the latest AR Foundation features.
Tape Drive If you’re interested in learning more about how we can help you with your Unity AR Foundation projects, or if you want to discuss a potential purchase of our services, don’t hesitate to reach out. We’re always happy to have a chat and see how we can work together to create something awesome.
References
- Unity official documentation on AR Foundation
- Various online tutorials and forums related to Unity and AR development
Hyllsi Technology Co., Ltd.
Hyllsi Technology Co., Ltd. is one of the most professional unity manufacturers and suppliers in China, specialized in providing high quality products with low price. We warmly welcome you to wholesale or buy bulk discount unity in stock here from our factory. For more cheap products, contact us now.
Address: Room 404, Building 1, Xingchen Building, Vanke Xingcheng, Shangxing Road, Shenzhen, China.
E-mail: sales@it-hyllsi.com
WebSite: https://www.it-hyllsi.com/