eos_plugin_for_unity
eos_plugin_for_unity copied to clipboard
fix: Android Threading & IO in Unity
The Problem: Unique IO Requirements in Unity on Android
In Unity on Android devices, IO operations must be performed using UnityWebRequest, whose internal Create function must be called from the main thread.
In version v3.3.3, we re-implemented async functions using Task.Run to execute asynchronously. This allowed code to return to the main thread seamlessly and simplified the codebase by reducing branching.
However, this approach doesn't work on Android because Task.Run still executes async functions on a background thread, conflicting with UnityWebRequest.Create needing to run on the main thread.
The Solution
We reworked the async functions to use only synchronous methods, avoiding the use of background threads.
Changes made:
- Updated naming conventions to clearly distinguish between asynchronous and synchronous functions.
- Used compiler conditionals to exclude asynchronous IO functions when running on non-editor Android platforms, preventing accidental usage.
- Replaced synchronous counterparts to asynchronous functions with implementations that do not use background threads, ensuring seamless operation for the caller without violating Android's main-thread requirements.
This PR addresses issue #941
#EOS-2167