Search Unity

Using Addressables for platform-specific assets (and for excluding irrelevant assets)?

Discussion in 'Addressables' started by JesseSTG, Jul 17, 2019.

  1. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    I'm making a game that I intend to release on multiple platforms. However, some of the game's assets are irrelevant on certain platforms; to save space, I don't want to include assets on platforms that don't use them. Sometimes I want to drop these assets entirely, such as an image of a keyboard that won't be used on the mobile versions. Other times I want to use a variant, like a version of my pause menu prefab that won't have a resolution selection slider on game consoles.

    I may also have builds of my game with extra features for certain purposes, like a demo version that lacks certain assets, or special free builds with people's names overlaid to mitigate leaks.

    I'm not interested in loading assets from the network; everything will be loaded from disk.

    Can the Addressables feature help me with this?
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    There's no standard way to deal with variant, it can be complex depends on how deep you go.

    However for including/excluding assets, you can use group/labels as workaround. For example, your app has two target platforms (mobile/desktop), and two feature sets (full/demo). It means four variants: mobile-full, mobile-demo, desktop-full, desktop-demo in logic.

    1. mark your assets with four labels: mobile, desktop, demo, full.
    2. change the default bundle mode to pack-by-label. It will create an asset bundle per unique labels. For example

    demo-mobile.bundle # for asset in mobile-demo
    demo-mobile-full.bundle # for asset in mobile-demo, mobile-full
    ... all sorts of mixins.

    When you have more labels for other purposes, you will get more mixin labels in bundle file.

    3. Then you need create a post-processing script to include necessary bundles for your variants.

    mobile-full, include bundle with mobile & full
    mobile-demo, include bundle with mobile & demo
    desktop-full, include bundle with desktop & full
    desktop-demo, include bundle with desktop & demo


    Be aware that you have to mark labels carefully. For example asset with label "mobile" only will not appear in any variants. Unless you changed to "mobile, full, demo" to make it available for all mobile variants. Because the semantic of step 3.

    You can also mix group and label, for example group for feature-set and label for platform. And find an include/exclude semantic in step 3 to make your life easier.

    There's a bug about pack-by-label, and will be fix in next release https://forum.unity.com/threads/cas...ogetherbylabel-wont-work.694987/#post-4747748

    Personally, I'm not that happy with this approach. I use label to load a group of assets by game logic. Adding variants to label make it more messy. I prefer variants as an independent feature in future.
     
    crekri likes this.
  3. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    Thank you, I appreciate it.

    I also noticed in your signature that you have an editor tool to simplify importing addressables. Do you think it suits my use case?
     
  4. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    I think so, just create a generic rule like *-mobile* to add "mobile" label to all assets matched.
     
  5. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    I'll try it out, thank you! When I get something working (with or without your tool), I'll report back here with my experience.
     
    Favo-Yang likes this.
  6. ChakibChemso

    ChakibChemso

    Joined:
    Jun 25, 2019
    Posts:
    8
    Then you didn't lol
     
  7. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    A little bit crass, but you're right.

    See this thread for what I wound up doing. (The thread turned out to be a duplicate but I didn't realize that.)
     
    MihaPro_CarX and piersb like this.