Search Unity

What is the intended best practice for loading assets using Addressables?

Discussion in 'Addressables' started by wheee09, Jul 22, 2018.

Thread Status:
Not open for further replies.
  1. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Hi all,

    So about 2 months into using Unity and it looks like I've started at an interesting time!

    Right now, I have a question about the intended way for using Addressables.

    I understand the reasoning why the loading and instantiating of assets is an async operation. But it makes me curious what the best practice is in the scenario of using assets within a scene.

    Approach 1: lazily load assets on demand within the scene.

    This means you have a number of callbacks scattered throughout the code, but more importantly, is it possible it can cause laggy glitches here and there? Imagine, a first-person shooter where you shoot an automatic rifle. You would load the bullet asset and then instantiate the game object each time you press the trigger and then unload the asset. Which doesn't seem ideal given that this is an automatic rifle...

    Am I being too paranoid with the time it would take to load the asset?

    Approach 2: load all assets that may be required by the scene when the scene is being load.

    This would mean that you can utilize a progress bar/loading screen and can handle remote and local assets equally. The scene would be responsible for ensuring that the cache of assets is removed on unload.


    Thanks!
     
  2. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    You should always preload your assets.

    Even if the memory is a concern, you should pre-load your asset at the latest moment possible. With your rifle example you would preload the bullets, when the player switches to the said rifle - when memory is a concern. If you don't care about memory that much, you just preload the asset on scene load or even application load.

    Loading asset for the first time at the moment you actually need it is a recipe for not-so-smooth gameplay :) .
     
  3. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Thanks for the response, that was my hunch as well!

    Makes me wonder now... how much memory does a prefab GameObject take... and how many is too many. I guess it depends on the mesh/materials/etc that is referenced by the GameObject.
     
Thread Status:
Not open for further replies.