Search Unity

AssetBundle and PhysicMaterial?

Discussion in 'Asset Bundles' started by MikeUpchat, Jan 27, 2019.

  1. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Just trying to use AssetBundles for the first time but got a problem. I have my test object loading from a bundle just fine but the materials, textures and most importantly for me the Physic material all seem to be new objects and not using the ones already present in the scene. Does this mean if I had a dozen Asset Bundles which happen to share the same textures that when I load those bundles into my scene the textures will be duplicated a dozen times?
    Do I need to write a script that hunts out all the materials, textures and Physic Materials and replace them with ones already in the scene or is there something I am missing.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    If you want to share assets between asset bundles, you need to put those shared assets in a separate bundle.

    https://docs.unity3d.com/Manual/AssetBundles-Preparing.html

    https://unity3d.com/learn/tutorials/topics/best-practices/assetbundle-usage-patterns


    Asset bundle dependencies make loading a little more complicated, because you need to load the bundle dependencies first. You had to in Unity 4.x at least, but I think it didn't change. For example, imagine you have these bundles:
    • prefabBundle (depends on materialBundle, textureBundle and physicsMatBundle)
    • materialBundle (depends on textureBundle)
    • physicsMatBundle (no dependencies)
    • textureBundle (no dependencies)
    In order to load the prefabBundle, you need to load bundles in this order:
    1. Load physicsMatBundle (no dependencies)
    2. Load textureBundle (no dependencies)
    3. Load materialBundle (must be loaded after textureBundle, because it depends on textureBundle)
    4. Load prefabBundle (since all bundle dependencies are loaded at this point)

    BTW, there is also a dedicated asset bundles forum:
    https://forum.unity.com/forums/asset-bundles.118/