immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
221 stars 43 forks source link

Saving to Quest prior to finishing experiment #119

Open mrstruijk opened 2 years ago

mrstruijk commented 2 years ago

Hi there,

In the wiki it is mentioned that on Standalone Quest: "When you run a UXF application, it seems currently to only save data if you do not quit mid-way through the experiment.".

Do you know of any way around this? I'm running a study which only uses 1 (long) trial. My aim is of course for all participants to reach the end of the study, but something might come up causing the program to quit prematurely. I'd like to have their data stored even if the app crashes, or they exit out early.

I've tried setting the Session.instance.EndCurrentTrial(); at OnApplicationQuit and OnDisable, but to no avail. However, if I run that same code in for instance a coroutine with a set timer, and then close the app a little while later, the data does get saved.

Best, Maarten

jackbrookes commented 2 years ago

I haven't done extensive testing, but I think it can be assumed that this is somewhat unavoidable. Oculus Quest does not allow Unity apps to cleanly shut down:

https://forum.unity.com/threads/onapplicationquit-and-ondestroy-is-not-executed-when-exit-app-on-oculus-quest.795942/

However I think there is very little chance of app crash, the Unity engine is pretty stable in general. You could (a) split into smaller trials (the user won't notice), or (b) have some button the user presses/holds to cleanly exit.

Some are suggesting OnApplicationPause, but this will invoke any time you press the Oculus Menu. So you could tell users not to press the Oculus Menu or the experiment will end.

https://stackoverflow.com/questions/55584865/onquit-event-in-oculus-go-app-made-in-unity

mrstruijk commented 2 years ago

Hi Jack,

Thanks for the reply. Your suggestions are excellent, I'll look into those.

Option A I don't quite understand. The issue is that the data doesn't get saved until the full Session is completed, right? So then creating smaller Trials doesn't solve my problem, or am I missing something obvious? Can I also write the files after each Trial?

OnApplicationPause might be a solution indeed. I could theoretically start a new Session if the pause-button was hit accidentally, and have that saved under a second Session number.

Small suggestion regarding the Wiki: could you make the explanation about Quest not quitting gracefully a little more prominent? I must admit I'm a hasty reader, but I missed that comment completely, and tried for a couple of frustrating hours to get it to work.

I'll post some updates once I've tried some of your solutions.

Thanks Jack, Best, Maarten

jackbrookes commented 2 years ago

Regarding option A: Data files that a per-trial (e.g. trackers) get saved at the end of each trial.