Search Unity

Best Practices?

Discussion in 'Addressables' started by wheee09, Jan 14, 2019.

  1. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Hi,

    Is it possible to compile a list of best practices/guidelines - especially one that is future-friendly?

    Some things of note include:
    1. load/release of assets and general cleanup/profiling for memory leaks, etc.
    2. what's more ideal (or future friendly) - load/release and Object.Instantiate or Addressable.Instantiate?
     
  2. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @wheee09 Addressable:instantiate and Addressable.Destroy means the Addressables do reference counting, Object.Instantiate means you have to do it on your own. That holds for most Addressables.Foo() methods. They are meant to replace the Object.Foo() methods in many cases if you do not want to do some special thing.
     
  3. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    @MNNoxMortem I suppose it depends on what you're doing. From what I read, it sounds like if you want to batch up some external assets and put them behind a loading screen for eager loading/preemptive caching then you would want to use Addressable.LoadAsset(s).

    Given that Instantiate from either Addressable or Object will return the newly instantiated object, there's really nothing you can do with one and not the other - post-instantiation.

    I guess for my project, I'm trying to devise one solution that will handle all of my use cases - and it sounds like handling the ref counts myself and using Addressable.LoadAsset(s) is the way to go.

    ...unless I can use Addressable.Instantiate into a special "asset caching" Scene and use that as a reference/dictionary for prefabs? Never tried to instantiate an object from the originating prefab of an instance of a gameobject before... apparently it seems like it's difficult to get the originating prefab from an instance of a gameobject...
     
  4. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    That is exactly the difference between those two. If you do want Unity to handle loading, unloading, reference counting behind the scenes use "Addressables" if you want - otherwise do it yourself with Object