Ar foundation stopped working all of a sudden on Android

Actually @Alex_Heizenrader I see that you did not attach a repro project to the bug. We have not yet experienced this issue in any of our tests, so I believe there is something in your project that is changing the session state to induce the crash. Your issue may be closed if our QA team is unable to reproduce it. Please attach a project to the bug that reliably reproduces the issue.

Edit: oh right, the unique issue here is that you are calling Reset while a session is initializing. That said it will help our QA team greatly if you can put a project together with a script that triggers the crash.

Is there any news on this? We are basically experiencing the exact same issue, where calling arSession.Reset() during initialization causes a crash. This only occurs after upgrading to Unity 2022.3 / ARFoundation 5.1.3. (previously we were using Unity 2021.3 / AR Foundation 4.2.6 and we did not experience this issue)

@Alex_Heizenrader 's bug has made it through triage: Unity Issue Tracker - [XR][Android] Player crashes when ARSession.Reset() is called after ARSession is instantiated on the device

We’ll get this work assigned to an engineer, thanks for the report.

So question ?:raising_hand_man:t5:
Where you able to find this in the XR Orgin script or AR Session script ?

And from what you’d said it looks like if we take out the ARSession.Reset then do it after it initializes then we should be ok and the app should stop crashing .

So basically I can either do that function separately outside that script or call for that function last after everything is initiated.

I’m currently looking to test this theory and see if that works . Any suggestions will be appreciated!

We have had this issue for some time now and went back to iOS development now that we are done with it we was hoping we gave some time for them to fix it . Now it’s time to take matters in our own hands if possible.

EDIT : SAME DAY

After testing this out and debugging the changes and updates in code and with a little help from chat gpt . I realized in the older version of my app (unity 2019) I am using addressables for my tracked images and we had to call for the ARsession to rest in iOS to make sure users always had the most updated tracked images . IOS Can handle this while the AR session is being created but Android can not .

Apparently if we call this when the android system is building the Ar.Session it will crash . So between me a chat gpt we came up with a solution too either make the reset for IOS only or make a delay for is if it’s android. here is the summary I hope this helps . We have been working on this for a week and a half now !

!!! NOTE !!! if you have made a script you have added the ARSession.Reset then you must edit it with the same constraints as my script making it have a delay or not do it for android at all

Issue Summary

The original issue involved crashes occurring on Android devices when attempting to reset the AR session during initialization. This reset was part of a script designed to dynamically update an XR tracked image library from Unity Cloud, a necessity for iOS devices to ensure they always had the most up-to-date XR library. However, on Android, this reset would cause crashes if called while the AR session was still initializing. On iOS, the reset operation worked without issues, but Android’s initialization process couldn’t handle it, leading to instability.


Original Script

The original script attempted to reset the AR session immediately after starting, which worked well on iOS but caused issues on Android.

csharp

Copy code

using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class ARSessionRest : MonoBehaviour
{
    [SerializeField]
    private ARSession arSession;

    void Start()
    {
        arSession.Reset();
    }
}

Issue with Original Script:

  • iOS: The reset operation was successful, ensuring that the most recent XR library was loaded without any issues.
  • Android: The script caused crashes because it attempted to reset the AR session while it was still initializing.

Updated Solution Options

To resolve this issue and maintain functionality across both platforms, two different solutions were implemented:

  1. Platform-Specific Delayed Reset Script: This solution applies a delay before resetting the AR session on Android devices, ensuring the reset only occurs after the AR session is fully initialized. On iOS, the reset happens immediately as before.
  2. Platform-Specific Reset Script: This solution makes the reset platform-specific, where the reset only happens on iOS and is completely skipped on Android. This ensures stability on Android while retaining the necessary functionality on iOS.

1. Platform-Specific Delayed Reset Script

This script ensures the reset operation is delayed on Android until the AR session is fully initialized, while iOS performs the reset immediately.

csharp

Copy code

using System.Collections;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class ARSessionRest : MonoBehaviour
{
    [SerializeField]
    private ARSession arSession;

    void Start()
    {
#if UNITY_IOS
        // Directly reset for iOS as it handles this well
        arSession.Reset();
#elif UNITY_ANDROID
        // Delay the reset until the session is fully initialized on Android
        StartCoroutine(WaitForSessionAndReset());
#endif
    }

    private IEnumerator WaitForSessionAndReset()
    {
        // Wait until the AR session is fully initialized
        while (ARSession.state != ARSessionState.SessionTracking)
        {
            yield return null;
        }

        // Once the session is tracking, reset the AR session
        arSession.Reset();
    }
}

Explanation:

  • iOS: The reset is performed immediately as iOS handles this operation well without causing crashes.
  • Android: The reset is delayed until the AR session is fully initialized, preventing the crashes that occurred due to the reset being called too early.

2. Platform-Specific Reset Script

This script performs the reset operation only on iOS and skips it entirely on Android.

csharp

Copy code

using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class ARSessionRest : MonoBehaviour
{
    [SerializeField]
    private ARSession arSession;

    void Start()
    {
#if UNITY_IOS
        // Perform the reset only for iOS
        arSession.Reset();
#elif UNITY_ANDROID
        // Skip the reset entirely for Android
        // The AR session will continue without resetting
#endif
    }
}

Explanation:

  • iOS: The reset is performed as needed to dynamically update the XR library.
  • Android: The reset is skipped to prevent crashes, ensuring stability on this platform while still running the AR session.

Outcome

With these two updated scripts, you can choose the approach that best fits your needs:

  • Platform-Specific Delayed Reset Script: Ensures the reset is handled carefully on Android by delaying it until the session is fully initialized, while maintaining immediate resets on iOS.
  • Platform-Specific Reset Script: Skips the reset on Android entirely, avoiding potential issues while still performing the necessary reset on iOS.

Both solutions maintain the functionality required for iOS devices while ensuring that Android devices no longer crash during the AR session initialization. I hoped we helped out !

Check us out at GameWorlds.online for our future projects !

1 Like

@GameWorldsDev Thank you so much for your provided Snippet!

The bug still persists in newer Version of AR Foundation. :confused:
Unity: 2023.2.9f1
AR Foundation: 5.1.5

1 Like

Since you use Unity 2023.2, try to update to the latest patch of Unity 6: 6000.0.16f1 because Unity 6 is the next stage of this releases’ cycle.

However, it’s recommended to use Unity 2022.3 LTS for Production, but if you want to downgrade, there may be issues.

Hello everyone,

I have gone ahead and confirmed with the sample scripts and information provided here, that the filed bug linked by @andyb-unity above has indeed been fixed.

The next release of AR foundation for Unity 2022.3 – version 5.1.6 – will indeed have the fix, and there will no longer need to be a delay in issuing an ARSession.Reset() on Android/ARCore when starting a new AR session if that is what your code is designed to do.

1 Like

Hi Mike,

As of today ( 13. Nov) I am unable to find any Unity 2022.3 version that includes AR Foundation 5.1.6. Could you please share where I can find this version?
I do also not see anything regading this version here: Changelog | AR Foundation | 5.1.5

It’s not available in Unity 2022.3.51f1. It’s really frustrating that this issue still persists almost a year later.

Thank you in advance for your help!

If anyone has a idea how to use the script above I’m happy to work with this workaround for now but for me it doesn’t do a difference.

You really shouldn’t be reseting an AR session on the same frame that you create it. The best workaround for this issue is to not do this.

That said, 5.1.6 is currently scheduled to release in December.