- Home /
How to abort UnityWebRequest when exiting play mode?
When I exit play mode, I have a never-ending web request logging data into my console. How do I abort the web request when exiting play mode?
Use case:
I'm using web requests to communicate with https://lichess.org/ using their API, documented here: https://lichess.org/api
The data is streamed using nd-json, with one JSON object per line. The specific API I'm using is the TV feed: https://lichess.org/api/tv/feed which, when working, results in an endless stream of data.
I wrote my own DownloadHandler to handle endless streaming, which is working fine.
Edit:
For more context, I'm currently yielding the result of SendWebRequest() in a coroutine.
At first I thought it was a bug that my web request that I initiated from play mode wouldn't auto-abort when I exited, but I found this forum post: https://forum.unity.com/threads/unitywebrequest-continues-downloading-after-play-mode-exit.688846/ One of the Unity devs said it would be "a minimal amount of work ... to get that behaviour" but they didn't say how.