Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to allow assigning a specific asset to more than one Asset Bundle?

Discussion in 'Asset Bundles' started by JohnOknelorfDev, Nov 24, 2021.

  1. JohnOknelorfDev

    JohnOknelorfDev

    Joined:
    Oct 2, 2017
    Posts:
    20
    Hello, we are trying to assign a specific asset to more than one Asset Bundle (deliberately). However, the following exception appears
    As a result, Unity fails and doesn't produce any asset bundles. Is it possible to somehow allow assigning a specific asset to more than one Asset Bundle? For example, can we "disable" this check or exclude certain files from the check?

    Unity version: 2019.4.18f1 LTS


    Some description and background on why we want to do this:

    We want to include the debug information into our asset bundles. The debug information consists of various technical details about the project's current state (git state, configs used, etc), and this information is the same for all bundles. We save it to the file right before building the bundles and want to include it into each asset bundle.

    The current workflow: we have a script that prepares our asset bundles (creates an array of AssetBundleBuild instances, one for each asset bundle) and then builds them with a single call of BuildPipeline.BuildAssetBundles. This is where the exception appears since we are trying to assign that file with debug information to all asset bundles. So, at the moment, this workflow isn't working.

    Of course, we could call BuildPipeline.BuildAssetBundles for each AssetBundleBuild instance separately (prepare an instance, immediately build this single instance, then move to the next bundle) but that's not an option since, in this case, we lose quite a lot of benefits, e.g. the overall building time of all asset bundles drastically increases, also, the Manifest Bundle (the special asset bundle that is named after the directory where the asset bundles were built to) contains the information only for the latest built AssetBundleBuild instance, and so on.


    We would be very thankful for any help. Thank you very much!
     
    Last edited: Nov 25, 2021
    ClayDome likes this.
  2. Werido

    Werido

    Joined:
    Jan 15, 2017
    Posts:
    7
    I have the same problem, can anyone help?
     
  3. JohnOknelorfDev

    JohnOknelorfDev

    Joined:
    Oct 2, 2017
    Posts:
    20
    Still relevant for Unity 2021.3.11f1, any chance it will be addressed?
     
  4. PS_SuperJura

    PS_SuperJura

    Joined:
    Apr 3, 2018
    Posts:
    7
    Bump. Any chance we get this option?
     
  5. AndrewSkow

    AndrewSkow

    Unity Technologies

    Joined:
    Nov 17, 2020
    Posts:
    78
    Thanks for raising this scenario. I'm not aware of the full background of that error message, but one possible purpose of that is help guide users towards not duplicating content, e.g. to try to help encourage the more typical AssetBundle layouts.

    But there is also a technical reason we don't currently support that. If the same Asset is specified in more than one bundle then the build system would not know which one to pick if that asset is also referenced from other bundles.

    E.g. if you have asset X in both bundle A and bundle B, and bundle C has a scene or prefab that uses asset X then the current build logic would not know which one to pick. I know that in the scenario you mention you are intentionally repeating the asset in bundle C as well so that concern would not occur, so perhaps that could be supported some day as a special case.

    Its also already possible to duplicate an asset into each assetbundle, but you need to make sure it is referenced implicitly by something inside each bundle. For example if you had a main ScriptableObject that you want to duplicate into each bundle then you could define small reference ScriptableObjects that point that that ScriptableObject, with one of these "reference assets" created for each bundle. Because main ScriptableObject is not assigned to any bundle it will end up duplicated inside each of your bundles. That may be a bit awkward but I'm hoping that describing that sort of workaround might give you some ideas.

    I agree that doing separate builds as a workaround is not at all a satisfactory workaround.

    I hope this helps!