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

Asset Bundles with materials pull textures inconsistently

Discussion in 'Asset Bundles' started by michal_gjk, Jun 30, 2020.

  1. michal_gjk

    michal_gjk

    Joined:
    Aug 13, 2016
    Posts:
    69
    Hello!

    Materials sometimes do forcefully include the textures they refer to in their own asset bundles even if those textures are assigned to a different bundle.

    That causes the bundles to fail to load because they share an asset (the texture) with the same name between them.

    BUT! the case I'm actually interested in is:

    When you include a prefab and the material it refers to in the same asset bundle the material WILL NOT forcefully include the textures in the same asset bundle.
    They will only be included in the bundles they are assigned to and it will be possible to load them from those asset bundles in any order and even use them with asset bundle variants.

    My question is what does that depend on?
    Under what circumstances materials DON'T 'pull' textures to their bundles?
    Is it consistent across Unity versions?

    ------------
    scenario descriptions in case I wasn't clear enough:

    Scenario 1:

    Create a scene

    Create a prefab like a sphere and assign it to a bundle "Prefabs . none"
    Create a material; assign it to the prefab BUT assign different bundle name to it ex. "Materials"
    Create a texture; assign it as MainTex in the material and set yet another bundle ex. "HD textures"

    Build the bundles.

    The texture will be pulled to the material bundle and you won't be able to load "Materials" and "HD textures" bundles at the same time.


    Scenario 2:

    Same as above but put the prefab and the material in the same bundle ex. "Prefabs".

    Build the bundles.

    The texture will NOT be pulled to the "Prefabs" bundle and you WILL be able to load "Prefabs" and "HD textures" bundles at the same time.

    What gives?
    Any chance to hear from anyone actually implementing this in the native code as unfortunately there's nothing interesting to see in the managed code reference on github.