I can’t seem to find anywhere in the docs for either the netcode or the transport package about how to make simple web requests or subscribe to web sockets.
I don’t want to make a full blown multiplayer game I just want to connect with a rest API or have a simple response to server side events.
Has anyone taken a look at this? The UnityWebRequest API is built around yielding your requests in coroutines which are exclusive to monobehaviours. Is there any current solution to this in DOTS?
There is no DOTS native solution for web requests and web sockets yet. At the moment you have to use either the existing UnityEngine classes in a hybrid game or pure C# alternatives. You can still use DOTS/ECS for most of the logic, but not the actual sending of the requests.
We will look at supporting it in a performant, GC-free, non-hybrid way in the future, but I cannot say exactly when that will happen.
It wouldn’t be practical to really build this yourself at the moment. Because there is no low level native functionality exposed for this on the engine core you would need to build your own native, cross platform, thread safe implementation that you could build your higher level stuff on. My guess is at the time Unity exposes some core functionality for this they will have their own DOTS package for it. I think because this probably requires new tech on the core you could expect it to line up with one of the tech releases so maybe 2020.2.
The guys at Unity pointed me in the direction of this project: GitHub - MartinKral/Spherestroyer: [Unity Tiny] Spherestroyer- feedback is welcome
If you dig into it, the developer imports a JS framework from within Unity, and is then able to make requests to it via API calls. So you should be able to make pretty much whatever web requests you need using this sort of method, though I wouldn’t rely on them for realtime, just async stuff like getting a high scores list (as this dev does), posting scores etc.
@JakHussain why can’t you simply use HttpClient? Just store the Task it returns in a shared component and poll it for when it completes. You aren’t going to issue thousands of web requests, are you?