Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

DOTS Web Request and Web Sockets

Discussion in 'Entity Component System' started by JakHussain, Jan 16, 2020.

  1. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    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.

    Can anyone point me in the right direction?
     
    adammpolak likes this.
  2. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    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?
     
  3. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    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.
     
    Opeth001 likes this.
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
  5. dg_bby

    dg_bby

    Joined:
    Jun 20, 2017
    Posts:
    2
    Hi, just a bump on this subject - have there been any updates with regards to simple networking requests in DOTS?
     
    adammpolak likes this.
  6. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Could we also get any guidance on how we can set up basic dots web requests ourselves from scratch?
     
    adammpolak and kevdome3000 like this.
  7. BrendonSmuts

    BrendonSmuts

    Joined:
    Jun 12, 2017
    Posts:
    86
    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.
     
  8. dg_bby

    dg_bby

    Joined:
    Jun 20, 2017
    Posts:
    2
    The guys at Unity pointed me in the direction of this project: https://github.com/MartinKral/tiny-one-button
    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.
     
  9. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    61
    @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?