So question ?
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:
- 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.
- 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 !