Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

How to send a report to server when the game is being closed?

$
0
0
I'm writing a plugin for Unity which needs to `yield return UnityWebRequest.SendWebRequest()` at some points in the game session. Ideally, I also need to send such request if the user closes the game (e.g. by closing the window from the operating system where the game runs). ---------- Actually, for my case, either `onDisable`, `onDestroy` or `onApplicationQuit` would do, however it seems that I can't start a coroutine there because at application termination all gameObjects are getting destroyed and there is simply not enough time to process the web request: not in one frame, not even in a few frames if there were any "grace period" at application closure. How do games solve such issues? ---------- A solution that comes to mind is to try to send data regularly. However, I'm already doing that. So, the problem is with that last request which doesn't get sent because the application is getting closed abruptly. ---------- Another solution I could think of is to store data which needs to be send (e.g. to PlayerPrefs or to some file) and *on the next app launch* check if there is any data pending to be sent. However, this won't always work for my case because: 1. The game may never be launched again. The user may just uninstall it. So, data will be lost 2. My server has a max allowed time after which the request will be rejected, so it has to be sent within the game session or shortly after, not 1 month after ---------- Yet another solution: download an executalbe file which would launch in the background, and if the game is closed then in onApplicationQuit use `System.Diagnostics.Process` to run that executable and do the request. However, this is bad in 2 respects: 1. Can't work cross-platform (would need separate executables for Windows, Mac, Linux and other platforms - ideally I want the plugin to run on every platform to which Unity can deploy 2. Each executable would need to handle the network logic in its own way - a work overhead compared to the simple, unified interface Unity offers.

Viewing all articles
Browse latest Browse all 387

Trending Articles