cancel
Showing results for 
Search instead for 
Did you mean: 

How to capture exit event on exiting from the OS on Quest

HooverFly
Protege
Anyone know which event to handle to get in before the OS terminates the app in Unreal to do an auto save on exit?
On PC in Unreal the Game instance's Shutdown event works but not on Quest.

So the user scenario is when you click terminate app in the Oculus menu bar, how does the app know it's being terminated in Unreal?

4 REPLIES 4

ysquall
Protege

I try using "Application Will Terminate Delegate" or "Application Will Enter Background Delegate" but neither seem to work. any other solution?

dario.maciel
Adventurer

you need to enable the app to write on external storage (android permissions, i recommend doing this on begin play of the app),

meloin
Explorer

Because ouclus sdk didnt implement Application Will Terminate Delegate with oculus you need to use native java method in unreal. That what I did.

1. Added JNI native method at GameInstance as

extern "C" JNIEXPORT void JNICALL Java_com_epicgames_ue4_GameActivity_OnAppTerminated(JNIEnv* jenv, jobject thiz)
{
UPVPGameInstance::NotifyServerLeaving(); // this is static method

UE_LOG(LogTemp, Error, TEXT("ApplicationWillTerminateDelegate"));
}
2. Added UPL XML with code and included it on build:
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:android="http://schemas.android.com/apk/res/android">
<!-- optional additions to the GameActivity class in GameActivity.java -->
<gameActivityClassAdditions>
<insert>
<![CDATA[
private native void OnAppTerminated();
]]>
</insert>
</gameActivityClassAdditions>
<!-- -->
<gameActivityOnDestroyAdditions>
<insert>
<![CDATA[
OnAppTerminated();
]]>
</insert>
</gameActivityOnDestroyAdditions>
</root>

3. If you are developing multiplayer game and would like to notify server about that exit you need to send custom udp message on server (you can't do http because you need time for handshake and you have no time for it)