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

AsyncOperation in pure ECS?

Discussion in 'Entity Component System' started by kfconeone, Jun 16, 2019.

  1. kfconeone

    kfconeone

    Joined:
    Oct 3, 2013
    Posts:
    7
    I want to migrate my project to pure ECS, but the first problem I faced is AsyncOperation,like gameobject instantiating,assetsbundle loading,web request...

    Some new features like Addressables also need AsyncOperation to implement,does that mean I can’t use it in pure ECS?

    For now I use hybrid ECS to achieve my requirements,but in Project Tiny I can’t ignore this,is there any way to use AsyncOperation?

    And I don’t mean some substitute API, just good old AsyncOperation.
     
    Last edited: Jun 16, 2019
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    What's stopping you using async operations in a (component) system?
     
  3. kfconeone

    kfconeone

    Joined:
    Oct 3, 2013
    Posts:
    7
    For example,we have tons of package using StartCoroutine to load assets, and we also use StartCoroutine for our WebRequest, but these are all bound with Monobehaviour.

    I don`t know how could I do the tricks without Monobehaviour...
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    I ditched coroutines years before ECS was announced. It's hardly a requirement for asset loading.

    At least Addressables/AsyncOperation you can just to check IsDone in a ComponentSystem. It's really all the yield is doing under the hood or use the completed event like it's designed for.
     
    Last edited: Jun 17, 2019
  5. Trinary

    Trinary

    Joined:
    Jul 26, 2013
    Posts:
    395
  6. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Just do:
    Code (CSharp):
    1. protected async void OnCreate() {
    2.      var handle = Addressables.Load<MyAsset>("default");
    3.      await handle.Task;
    4.      myAsset = handle.Result;
    5. }
     
  7. kfconeone

    kfconeone

    Joined:
    Oct 3, 2013
    Posts:
    7
    yeah... I tried to use OnUpload() checking IsDone before, but it's a little bit laborious and not very flexible,so I abandoned that way at last.

    But I think I better take a review, thanks!

    Thanks! I'll take a good look at this.
     
    Last edited: Jun 17, 2019
  8. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Picking this up and running into this, on the MonoBeha
    • You cannot use ref locales within async methods, which is a problem when you need ref locales to capture ref returns from Dots code (e.g. Collider)
     
    Karabin likes this.