Search Unity

Feedback I feel like Load and Instantiate should be transparent to the user. Combine them?

Discussion in 'Addressables' started by RecursiveFrog, Sep 19, 2019.

  1. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    In my own games, I personally don’t want to have to track whether an asset bundle is loaded before I call Instantiate. To that end I find myself writing managers and loaders that make this transparent for me. All I want is something like

    Code (CSharp):
    1.  
    2.  
    3. // a method that implicitly loads a bundle of it isn’t loaded and then instantiates an instance of the asset.
    4.  
    5. var op = Addressable.Obtain<Foo>(assetRef);
    6. yield op.IsWorking;
    7. Foo foo = op.result;
    8. foo.DoFooThings();
    9.  
    10. // ... later after I’m done...
    11.  
    12. // either...
    13. Destroy(foo.gameObject);
    14. // or just let it be destroyed on a scene unload
    15.  
    16.  
    17. // ... later when I’m done with an asset ref ...
    18. Addressable.UnloadAsset(assetRef);
    19. //... and/or I’m done with all of them
    20.  
    21. Addressable.UnloadAllAssets();
    I grant you I don’t go as far as making the fancy yield operator but I should try one day.


    Point is, this kind of bookkeeping doesn’t seem necessary to load onto the end user. I just want instances of objects that I manage myself, and that’s it. I recognize that it’s also a good idea to be able to release bundle assets once they’re not needed, so I give myself that ability.
     
    Last edited: Sep 20, 2019