My image tracking unity AR project in working fine in unity itself when i test it in XR environment …but when i deploy it for android and install the apk in my phone it wont track the images
Have done everything like checking the Google ARCore for android and removing vulkun etc but nothing seems to work.
In your screenshot, you have 1 image in the Editor at the same time and 2 images at the same time in the build. These are different cases.
Did you try with the only image on the “AR Marker’s board” using the build?
You can provide your code to find the issue.
Check also my Tips for Multiple Image Tracking here.
thanks for responding,
in editor there are multiple images and all are being tracked but the other images are just out of the frame so you can only see the earth image
this is the free aspect ratio screen shot
but its not working in my android phone how can i fix it.
here’s the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.UI;
using TMPro;
public class ImageTracker : MonoBehaviour
{
private ARTrackedImageManager trackedImages;
public GameObject ArPrefabs;
List<GameObject> ARObjects = new List<GameObject>();
public TMP_Text infobox;
void Update()
{
outputTracking();
}
void outputTracking()
{
infobox.text = "Tracking Data: \n";
int i = 0;
foreach (var trackedImage in trackedImages.trackables)
{
infobox.text += "Image: " + trackedImage.referenceImage.name + " " + trackedImage.trackingState + "\n";
if (trackedImage.trackingState == TrackingState.Limited)
{
ARObjects[i].SetActive(false);
}
if (trackedImage.trackingState == TrackingState.Tracking)
{
ARObjects[i].SetActive(true);
}
i++;
}
}
void Awake()
{
trackedImages = GetComponent<ARTrackedImageManager>();
}
void OnEnable()
{
trackedImages.trackedImagesChanged += OnTrackedImagesChanged;
}
void OnDisable()
{
trackedImages.trackedImagesChanged -= OnTrackedImagesChanged;
}
// Event Handler
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
//Create object based on image tracked
foreach (var trackedImage in eventArgs.added)
{
foreach (var arPrefab in ArPrefabs)
{
if(trackedImage.referenceImage.name == arPrefab.name)
{
var newPrefab = Instantiate(arPrefab, trackedImage.transform);
ARObjects.Add(newPrefab);
}
}
}
//Update tracking position
foreach (var trackedImage in eventArgs.updated)
{
foreach (var gameObject in ARObjects)
{
if(gameObject.name == trackedImage.name)
{
gameObject.SetActive(trackedImage.trackingState == TrackingState.Tracking);
}
}
}
}
}
There are several updated resources to implement Multiple Image Tracking:
- Official Unity Examples with Multiple Prefabs for different versions of AR Foundation: v5, v6.
- My Example (paid asset) with Multiple Data (based on different Tracked Images) for the Only Game Object.
Don’t use the Update() function. You can do all operations in OnTrackedImagesChanged(). This is my base implementation of it:
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs args)
{
foreach (ARTrackedImage arTrackedImage in args.added)
{
DebugPrinter.Print("added. Name: " + arTrackedImage.name);
ShowContent(arTrackedImage, true);
}
// ----------------------------------------------------------------
// ARCore NOTICE from https://makaka.org/unity-tutorials/ar-testing
// ----------------------------------------------------------------
// ARCore API assumes that AR Images are static in the environment
// so once they are recognized successfully they will always appear
// in the list of anchors until the session is reset. This means that
// AR Foundation will never report that a tracked images is removed
// nor will a tracked image's tracking state be reported as None.
// args.updated contains all images that were added
foreach (ARTrackedImage arTrackedImage in args.updated)
{
if (arTrackedImage.trackingState == TrackingState.Tracking)
{
ShowContent(arTrackedImage, true);
}
else
{
ShowContent(arTrackedImage, false);
}
//DebugPrinter.Print($"upd." +
// $" State: {arTrackedImage.trackingState}." +
// $" Name: {arTrackedImage.name}");
}
foreach (ARTrackedImage arTrackedImage in args.removed)
{
DebugPrinter.Print("removed. Name: " + arTrackedImage.name);
ShowContent(arTrackedImage, false);
}
}

