unity-experiment-framework icon indicating copy to clipboard operation
unity-experiment-framework copied to clipboard

onSessionEnd is send before HTTPPost is finished

Open govertbuijs opened this issue 10 months ago • 4 comments

The tooltip for this event says "Items in this event will be triggered just as the session ends, after data has been written.". But the UnityWebRequest is done in a co-routine, therefor it's not guaranteed to be finished when the event is invoked. We can't use a Thread like in FileSaver, as the UnityWebRequest can only be fired from the main thread.

govertbuijs avatar Feb 24 '25 14:02 govertbuijs

Hey, I guess this is pretty similar to what I wanted here https://github.com/immersivecognition/unity-experiment-framework/issues/130, which I haven't attempted further because I solved my issues in differently. That being said, what exactly do you need to do?

Maybe you can make custom changes to UXF to make this work. As an example, I created custom csv builder as a co-routine that works in WebGL because the standard csv builder doesn't allow this. Maybe you can do something similar? You could try working with boolean variables that work across scripts.

JAQuent avatar Feb 25 '25 01:02 JAQuent

Yeah, it's the same thing. I want to close my app once all the transports are done.

I keep a counter of all active web-requests, and send a custom event once they're all done. Adding a new event might confuse users, as the session is already supposed to be done.

We could keep it internal with a listener and send out onSessionEnd once all transports are done.

govertbuijs avatar Feb 25 '25 09:02 govertbuijs

Let know if you figured it out because for now I just added an extra 1 Minute co-routine that waits before closing the application to make sure the data is send but this is obviously not an ideal solution.

JAQuent avatar Feb 25 '25 10:02 JAQuent

I've created an issue_176 branch in my fork.

The second to last commit invokes the TransportDoneEvent after all POSTs are done. No guarantees about success, and onSessionEnd might already be invoked.

The last commit defers the onSessionEnd untill all DataHandlers are done transporting. I think only the HTTPPost needs waiting, the others seem synchronous (not tested).

govertbuijs avatar Feb 28 '25 13:02 govertbuijs