Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Non async version

Discussion in 'Addressables' started by pointcache, Feb 11, 2019.

  1. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    500
    Is there a non async version?
    This code from samples :

    Code (CSharp):
    1.     public List<AssetReference> shapes;
    2.  
    3.     bool m_IsReady = false;
    4.     int m_ToLoadCount;
    5.  
    6.     int currentIndex = 0;
    7.     // Use this for initialization
    8.     void Start ()
    9.     {
    10.         m_ToLoadCount = shapes.Count;
    11.         foreach (var shape in shapes)
    12.         {
    13.             shape.LoadAsset<GameObject>().Completed += OnShapeLoaded;
    14.         }
    15.     }
    16.  
    17.     void OnShapeLoaded(IAsyncOperation<GameObject> obj)
    18.     {
    19.         m_ToLoadCount--;
    20.         if (m_ToLoadCount <= 0)
    21.             m_IsReady = true;
    22.     }
    23.  
    What if i don't plan to use cdn, is there a way to load the resources synchronously?


    Ok from what i gathered , sync was not implemented, but its planned, meaning it's at least half year away. Also system lacks commonly used methods of query.
    So what i'd do for now is mock adressable system myself with labels and such to use resources, and then swap when it's ready.
     
    Last edited: Feb 11, 2019
  2. tomekswk

    tomekswk

    Joined:
    Jun 11, 2015
    Posts:
    2
    Shouldn't really matter whether the asset is local or remote - why would you want to freeze your game while loading assets?
     
    RecursiveFrog likes this.
  3. Overing

    Overing

    Joined:
    Mar 1, 2015
    Posts:
    1
    Maybe you can try...

    Code (CSharp):
    1. public List<AssetReference> shapes;
    2. bool m_IsReady = false;
    3.  
    4. IEnumerator Start ()
    5. {
    6.     foreach (var shape in shapes)
    7.     {
    8.         yield return shape.LoadAsset<GameObject>();
    9.     }
    10.     m_IsReady = true;
    11. }
     
  4. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    500
    I need all dependencies to be preloaded. Im not doing coroutine mumbo jumbo for something so simple.
     
  5. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    412
    If you need everything preloaded, why do you want to use addressables?
     
    RecursiveFrog likes this.
  6. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    500
    It speeds up editor play times, it acts as a database, etc etc there are many benefits to it apart from downloading assets. The system solves many problems with bundles and management, but it seems the main selling point is aimed at mobile/browser developers so im met with confusion when i want to do things the standalone/desktop way.
     
  7. BinaryEclipse

    BinaryEclipse

    Joined:
    Sep 1, 2016
    Posts:
    14
    I just integrated it into my pooling system. So the pooling system creates the instances to be made readily available for getting instances non-async. And because addressables give it to you async, you can create more instances of a certain asset when you are running low, and you can do so without affecting performance. So the rest of you application can just get instances as though they were being instantiated.
     
    RecursiveFrog likes this.
  8. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    500
    So asset loading and instantiation are async? I was under impression that instantiation would behave in the same way it did before, with async part being initial asset load into memory.
     
  9. jonagill_ag

    jonagill_ag

    Joined:
    Jun 21, 2017
    Posts:
    11
    If you plan on everything to be loaded at once, then you can load all of your assets from addressables during a loading scene using LoadAsset, then instantiate them at runtime by using the standard, synchronous instantiation code to clone the loaded assets.
     
  10. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    500
    Ill just wait til sync is officially supported.
     
  11. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    441
    Oh boy, have I got news for you...! :-/
     
  12. BinaryEclipse

    BinaryEclipse

    Joined:
    Sep 1, 2016
    Posts:
    14
    I'm talking about "Addressables.Instantiate"
     
  13. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    441
    If the asset is loaded already, this will instantiate and call its callback synchronously.
     
  14. BinaryEclipse

    BinaryEclipse

    Joined:
    Sep 1, 2016
    Posts:
    14
    but the function returns an IAsyncOperation
     
  15. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    441
    A completed one, if I remember rightly. Do check.