Hello! I’m developing a mobile game that uses MARS face tracking, allowing users to tilt their head and close their eyes as inputs.
I’m running into an issue testing on device:
If the app moves to the background (the user locks their device screen, switches between apps, takes a phone call), upon returning to the app, the MARS Face Mask seems to get stuck, with all transform values frozen where they were when the app became inactive.
However, the EyeClosed/EyeOpened actions are still being triggered as expected.
I’ve tried utilizing OnApplicationPause with various combinations of solutions from other forum posts ( Turn Off MARS Camera , Reset MARS ), but it seems like the only reliable solution is to totally reload the scene, which is not desirable.
Is there a proper way to resume a MARS face tracking session after the app returns to the foreground, without having to reload the scene?
Here’s my code with various attempts commented out:
public class MarsSessionController : Singleton<MarsSessionController>, IUsesFunctionalityInjection, IUsesSessionControl//, IUsesPointCloud, IUsesPlaneFinding, IUsesMarkerTracking, IUsesFaceTracking
{
public bool IsActive { get { return !MARSCore.instance.paused; } }
public Transform FaceRoot { get { return faceRoot; } }
public Transform MarsCameraTransform { get { return marsCam.transform; } }
[SerializeField] private GameObject marsSystems = null;
[SerializeField] private Transform faceRoot = null;
[SerializeField] private MARSCamera marsCam = null;
IProvidesFunctionalityInjection IFunctionalitySubscriber<IProvidesFunctionalityInjection>.provider { get; set; }
IProvidesSessionControl IFunctionalitySubscriber<IProvidesSessionControl>.provider { get; set; }
//IProvidesPointCloud IFunctionalitySubscriber<IProvidesPointCloud>.provider { get; set; }
//IProvidesPlaneFinding IFunctionalitySubscriber<IProvidesPlaneFinding>.provider { get; set; }
//IProvidesMarkerTracking IFunctionalitySubscriber<IProvidesMarkerTracking>.provider { get; set; }
//IProvidesFaceTracking IFunctionalitySubscriber<IProvidesFaceTracking>.provider { get; set; }
protected override void Awake()
{
base.Awake();
// Only necessary if this script isn't already in the scene when you press Play
this.EnsureFunctionalityInjected();
}
public void InitializeMars()
{
if (marsSystems.activeSelf == false)
{
marsSystems.SetActive(true);
}
}
private void OnApplicationPause(bool pause)
{
if (pause)
{
PauseMars();
}
else
{
ResumeMars();
}
}
public void PauseMars()
{
if (MARSCore.instance.paused == false)
{
MARSCore.instance.paused = true;
//if (this.HasProvider<IProvidesPointCloud>())
//{
// this.StopDetectingPoints();
//}
//if (this.HasProvider<IProvidesPlaneFinding>())
//{
// this.StopDetectingPlanes();
//}
//if (this.HasProvider<IProvidesMarkerTracking>())
//{
// this.StopTrackingMarkers();
//}
//if (this.HasProvider<IProvidesFaceTracking>())
//{
// // ???
//}
this.PauseSession();
}
}
public void ResumeMars()
{
if (MARSCore.instance.paused)
{
MARSCore.instance.paused = false;
//if (this.HasProvider<IProvidesPointCloud>())
//{
// this.StartDetectingPoints();
//}
//if (this.HasProvider<IProvidesPlaneFinding>())
//{
// this.StartDetectingPlanes();
//}
//if (this.HasProvider<IProvidesMarkerTracking>())
//{
// this.StartTrackingMarkers();
//}
//this.ResumeSession();
this.ResetSession();
}
}
}