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

Do macOS and Windows need different asset bundles?

Discussion in 'Asset Bundles' started by dlegare-synapse, Apr 30, 2019.

  1. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    The documentation for
    BuildPipeline.BuildAssetBundles()
    states the following:

    Additionally, the documentation for the now-deprecated
    BuildPipeline.BuildAssetBundle()
    provides slightly more specific details:

    These make it clear that asset bundles built for standalone targets cannot be loaded (and vice versa), and that Android and iOS cannot load bundles for the other platform. However, how well does compatibility between the standalone platforms work? Specifically:
    • Do I need to build separate bundles for macOS and Windows? Or can a build a single "Standalone" bundle and have it work for both?
    • Are there any drawbacks to sharing bundles between the two? e.g would the generated assets not be able to take advantage of platform-specific technologies like Metal on macOS?
    • Are there any guarantees about compatibility between platforms? Or is compatibility subject to change in future versions of Unity?

    Note that I'm primarily asking about macOS and Windows because our game needs support for both, however other people may also be curious about how Linux support fits in as well.
     
    ereishus likes this.
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    Asset Bundles contain platform specific serialized data. This means the short answer is, no, bundles for one platform will not work on another platform.

    The long answer: It's complicated. Bundles that contain types that are are identically serialized on both platforms would actually be cross platform compatible. The complicated part is figuring out which types those are and getting only those types into cross platform compatible bundles. I can only think of a handful of non-useful types that fall into this grouping atm, so generally speaking it is safer to say they are not compatible.
     
    dlegare-synapse likes this.
  3. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
  4. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    A follow-up question on this: Do we need different asset bundles for different target architectures on the same platform? For example,
    StandaloneWindows
    vs
    StandaloneWindows64
    . I assume not for a couple of reason:
    • Some platforms (e.g. Android) don't actually differentiate between target architectures in the
      BuildTarget
      enum, so for those platforms it doesn't seem possible to make different bundles for the different architectures.
    • The
      RuntimePlatform
      enum doesn't differentiate between architectures for a given platform, so if I were running a standalone Windows build, I wouldn't be able to tell whether I need to use the 32 bit or 64 bit bundles for my game.
    However, someone else has reported that asset bundles have different hashes based on the target architecture, which means even if the architecture doesn't matter at runtime, we still need to be consistent about what how we specify the target architecture when building bundles. For example, even if we're building players for both
    StandaloneWindows
    and
    StandaloneWindows64
    , we should only build asset bundles once for
    StandaloneWindows
    and then use those bundles for both players. Is that correct?
     
  5. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    An additional followup question: Do I need different asset bundles for
    WSAPlayer
    builds vs
    StandaloneWindows
    builds? I would expect not, but nothing that I've found in the documentation specifies one way or the other.
     
  6. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    These are tough questions as I don't have insight into every serialized type that could be placed in a bundle and if it has any platform specific needs.

    That being said, the only architecture specific content I'm aware of today is for WSAPlayer as that does have a large range of target devices that actually do care about architecture specific content. The rest of the platforms though I'm not aware of anything today that is 32 bit vs 64 bit specific in serialized content, however I do know that this will change as there are some things in the works that will be architecture specific.

    For getting architecture at runtime, the RuntimePlatform enum has architecture options for WSAPlayer. For other platforms you can use SystemInfo.operatingSystem. We probably should add a runtime api to get just the Architecture instead of having to rely on the operating system return or the runtime platform enum. I'll add that feature to the feature tracker.
     
    dlegare-synapse likes this.
  7. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    @Ryanc_unity Thanks for the information! I'd absolutely appreciate an API for getting runtime architecture, especially if it's a value that's actually needed at runtime to differentiate between things like asset bundles :)

    For situations where target architecture matters when building/loading asset bundles (e.g. WSA today, maybe other things in the future) what's the best way to control how bundles are built/loaded? For example, at runtime I have different variants in
    RuntimePlatform
    that I can use to differentiate between different WSA architectures, but the
    BuildTarget
    enum used when building bundles doesn't include the architecture. How would I specify which architecture to target when building bundles for WSA?
     
    Last edited: Aug 21, 2019
  8. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    EditorUserBuildSettings.wsaArchitecture
    Took me a bit to find the api...which usually indicates we should improve that =(
     
    dlegare-synapse likes this.
  9. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    Ah yeah, that's unfortunate :( For other platforms, the architecture is in the
    BuildTarget
    enum, so it's not evident when building bundles for WSA that architecture matters, even though from what you're saying it's the platform where it matters the most. Thanks for clarifying, though!
     
  10. The-Lemur

    The-Lemur

    Joined:
    Jan 23, 2015
    Posts:
    2
    Question: When building the asset bundles: Can I build assets for iOS devices while on a Windows Computer? I have imported and switched the build settings over to be iOS, but I know that Apple can be strict and finicky at times.
     
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    Yes, asset bundles are our own format and has nothing to do with Apple. You can build bundles for any platform as long as you have required platform support in editor.