Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ScriptableObject as in Ryan Hipple use case

Discussion in 'Addressables' started by Paul_H23, Jul 22, 2019.

  1. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    I've been building something out that uses the various patterns described in Ryan Hipple's Unity Austin 2017 talk, i.e. using ScriptableObject for things like shared variables, enums, events etc. It all worke well, right up until I chose to use AddressableAssets for managing remotely loaded assets. The game I'm creating will rely heavily on backend served content updates, so AddressableAssets is an ideal choice to manage this, at least on the surface. However, I've hit some issues with the combination of SO and AA that I can't seem to find a tidy and manageable way round, any thoughts from the AA experts would be great. An example might help explain the problem

    I have a bunch of simple SOs defined for item "archetype", and a bunch of scripts on items that can perform actions based on interactions between items of different archetypes. I've been building this out by having a simple component that defines an items archetype, and scripts that define action lists, each one has a "Archetype" public field, that I drag and drop the SO onto. Unfortunately, what happens as soon as I move the items into an AssetBundle via AddressableAssets, is each thing gets it's own idea of what the archetype SO is, so the simple comparison of SO model doesn't work anymore. I could do a string comparison of a field on the SO enum, but that just "feels" wrong, and goes against a lot of the benefits that Ryan described in his talk. I could switch to an AssetReference model, but then the assets (SOs) themselves need to be resolved and loaded asynchronously at some point, and it's then challenging to work out when a loaded item is fully loaded and can take part in the game. Any code that checks the archetype has to presume that it has been loaded, so the order of execution becomes an asynchronous nightmare.

    This is just one element of complexity the async only nature of AA is introducing, does anyone have any experience of working in this way, where the loading of assets is critical, not just a nice to have? i.e. loading a texture and having it show when it's available is not a big deal, but loading a critical identification asset and not knowing when it's available to be queried, not so much.

    Cheers


    Paul
     
    Colin_MacLeod likes this.
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    it goes down to the underlying AssetBundles used.
    basically if any asset is both in the build (e.g. referenced in a scene in Build Settings or Resources) and in an asset bundle (directly or indirectly) then it gets duplicated and there is no workaround (if an asset is duplicated between AB instead, then you can assign it explicitly to an AB and it gets referenced).

    what you could do is have everything into asset bundles / addressable, then put in build settings only a bootstrap scene that loads the actual first scene via Addressables.
    put everything that should have been in the build into a local group
     
    Paul_H23 likes this.
  3. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    Thanks, that's pretty much the same conclusion I came to, I had been making some assumptions that weren't clearly defined in the documentation anywhere, but found them in the end by poking around in the dark.

    AddressableAssets is definitely an interesting system, but really needs to be integrated better with the editor, not to mention better docs, fingers crossed for the future.