cancel
Showing results for 
Search instead for 
Did you mean: 

Our solution to saving when power runs out

emalafeew
Protege
Others have asked how to detect when the Go is about to shutdown due to low battery or overheating, so that accumulated game state can be saved then.

We know OnApplicationQuit() and OnDestroy() aren't called, and didn't see related events sent by OVRManager.  Some people have tried monitoring battery level and temperature on OVRManager, but haven't found them reliable indicators of when the Go will shutdown.

We initially tried handling "android.intent.action.ACTION_SHUTDOWN" from a native plugin, but according to the logs was called after our app was closed.  But we noticed that "android.intent.action.ACTION_REQUEST_SHUTDOWN" seems to be called in time, and so that's our solution for now!

You'll need to put something like this in an Android java plugin:

public class MyReceiver extends BroadcastReceiver {
...
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.ACTION_REQUEST_SHUTDOWN")) {
UnityPlayer.UnitySendMessage("YourGameManager", "Shutdown", "");
}
}
};

which you handle in a GameObject named "YourGameManager" with
void Shutdown(string reason) {
// Save your game state
}

Hope this helps anyone and keeps working!
0 REPLIES 0