AR Object keeps drifting after placing on ground plane in AR Foundation

Hi everyone,

I’m relatively new to AR development and followed this Unity documentation (AR Anchor Manager component | AR Foundation | 5.1.5) for anchoring objects in AR. However, I’m experiencing issues with my game’s stability.

When I test my game on my mobile device, the objects are not stable and tend to move with the camera (mobile) movement. Sometimes they even shift from one location to another far away, which is not expected behavior. Everything seems fine in the simulation, but the issues arise during actual mobile testing.

Here’s some relevant information:

  • Device: Samsung Galaxy A34 (no depth sensor)
  • Unity Version: 2022.3.15f1
  • AR Foundation Version: 5.1.5

Here is the code snippet:

void Update()
    {
        if (!TryGetTouchPosition(out Vector2 touchPosition))
            return;

        if (isPlaneDetectionEnabled && m_RaycastManager.Raycast(touchPosition, s_Hits, TrackableType.PlaneWithinPolygon))
        {
            // Raycast hits are sorted by distance, so the first one will be the closest hit.
            var hitPose = s_Hits[0].pose;

            if (spawnedObject == null)
            {
                // Check if currentLevelIndex is within bounds before instantiating the prefab
                if (currentLevelIndex >= 0 && currentLevelIndex < m_PlacedPrefabs.Length)
                {
                    // Instantiate the prefab at the hit position and rotation
                    spawnedObject = Instantiate(m_PlacedPrefabs[currentLevelIndex], hitPose.position, hitPose.rotation);

                    // Apply rotation correction if needed
                    spawnedObject.transform.rotation = Quaternion.Euler(0f, 0f, 0f);

                    characterController = spawnedObject.GetComponentInChildren<CharacterController>();

                    Debug.LogWarning(currentLevelIndex);

                    // Attach an ARAnchor component to the spawned object
                    objectAnchor = spawnedObject.AddComponent<ARAnchor>();
                    objectAnchor.transform.position = hitPose.position; // Ensure anchor is at the hit location
                }
		.
		.
		.
            }

            else
            {
                // Reposition the anchor 
                if (objectAnchor != null) 
                { 
                    objectAnchor.transform.position = hitPose.position; 
                }
		.
		.
		.
            }
	    .
	    .
	    .
        }	
    }

Thanks in advance.

A71 also has such issues.
These are low-budget devices, and tracking on them is not good enough.

Moreover, ARKit provides better results in comparison to ARCore.


To improve tracking:

  1. Run the app in the room with Good Lighting.
  2. Turn Off Power Saving mode that cut up to 70% of CPU speed.

Thank you so much for your response.

I play Angry Birds AR: Isle of Pigs on my device, and I’ve noticed that it maintains excellent plane tracking and firmly stays on the ground. As far as I know, it’s developed using Unity. Do you have any insights on how they manage to maintain such reliable tracking on low-budget devices?

They could use other AR Engines in Unity: Vuforia, Wikitude, etc…

If you are looking for a ground truth about the performance of ARCore on your device, I recommend running an ARCore sample app that isn’t built with Unity. Google has a number of these available: Sample Apps with ARCore  |  Google for Developers

If you notice discrepancies between Unity’s implementation of ARCore and the ARCore data you see outside of Unity – note that we aren’t aware of any such issues at this time – please file a bug. Unity QA: Building quality with passion

It is indeed possible that the Angry Birds app is using some other technology besides ARCore. Not sure!