Search Unity

Texture share in AssetBundle

Discussion in 'Asset Bundles' started by SuperNbie, Oct 14, 2019.

  1. SuperNbie

    SuperNbie

    Joined:
    Nov 1, 2012
    Posts:
    15
    We are working on AssetBundles.
    I ask about texture sharing.

    There are two materials and one texture in the attached project file.
    Both materials use the same texture.

    Run Assets-> Build Asset Bundle to create a bundle in the NewBundle folder.

    If you look at the folder, it looks like the material bundle contains textures, right?

    Does Unity's AssetBundle system currently support sharing with textures? Or do I need to create a bundle in another way?
     

    Attached Files:

  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374

    I ran your project, the resulting manifest is this:

    Code (CSharp):
    1. ManifestFileVersion: 0
    2. CRC: 3901782163
    3. AssetBundleManifest:
    4.   AssetBundleInfos:
    5.     Info_0:
    6.       Name: sharedtexture
    7.       Dependencies: {}
    8.     Info_1:
    9.       Name: b
    10.       Dependencies:
    11.         Dependency_0: sharedtexture
    12.     Info_2:
    13.       Name: a
    14.       Dependencies:
    15.         Dependency_0: sharedtexture
    16.  
    This appears correct. Three bundles were built, one for each material and they both list the sharedtexture bundle as a dependency. This means your texture asset is built only once and is correctly referenced. What were you expecting to see?
     
    SuperNbie likes this.
  3. SuperNbie

    SuperNbie

    Joined:
    Nov 1, 2012
    Posts:
    15
    Thank you for answer.

    The dependency information in the manifest file is correct.

    But, the size of the bundle file created is strange.

    The material bundles a and b should be 2-3 Kbytes in size,

    The bundle file to be used by the patch system is as large as the texture file size.

    The bundle file size is similar for two materials and one texture. It looks like the material bundle contains textures.

    Is this normal?
     
    Last edited: Oct 14, 2019
  4. SuperNbie

    SuperNbie

    Joined:
    Nov 1, 2012
    Posts:
    15
    In the project attached above, there are three assets in the BundleAsset folder:

    1. A.mat -> BundleName: a (using NoceEffectGrame.png)
    2. B.mat -> BundleName: b (using NoceEffectGrame.png)
    3. NoceEffectGrame.png-> BundleName: sharedtexture (The file size of the texture is 192KB.)


    In the above state, if you create a bundle, the following bundle file is created.

    a (size 249KB)
    b (size 249KB)
    sharedtexture (size 203KB)


    The dependency information in the manifest file is correct.

    ManifestFileVersion: 0
    CRC: 5339008
    AssetBundleManifest:
    AssetBundleInfos:
    Info_0:
    Name: sharedtexture
    Dependencies: {}
    Info_1:
    Name: b
    Dependencies:
    Dependency_0: sharedtexture
    Info_2:
    Name: a
    Dependencies:
    Dependency_0: sharedtexture


    However, the file size seems odd.

    Is this the normal bundle size? Or is there a problem with the bundle creation process?
     
  5. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    I see the same as you, however try adding more textures and materials referencing them and you'll see the filesize of the materials won't get bigger, but the sharedtexture will. I have a suspicioni the materials are larger than expected because a copy of the shaders is included.
     
  6. SuperNbie

    SuperNbie

    Joined:
    Nov 1, 2012
    Posts:
    15
    Thank you for answer.
    Like you said, it seems to be related to Material and Shader,
    I tried to make a bundle using prefab, but things got worse.
    All assets have the same texture, and the manifest's dependency information is correct.

    Assetbundle resource

    1. A.mat -> BundleName: a (using NoceEffectGrame.png)
    2. B.mat -> BundleName: b (using NoceEffectGrame.png)
    2. C.prefab -> BundleName: c (reference NoceEffectGrame.png)
    2. D.prefab -> BundleName: d (reference NoceEffectGrame.png)
    3. NoceEffectGrame.png-> BundleName: sharedtexture (The file size of the texture is 192KB.)


    Created assetbundle size

    a 249KB
    b 249KB
    c 200KB
    d 200KB
    sharedtexture 203KB
     

    Attached Files:

  7. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
  8. MacroPinch

    MacroPinch

    Joined:
    Dec 6, 2013
    Posts:
    43
    Hi,
    Your issue looks similar to ours. You can see it here:
    https://forum.unity.com/threads/bug...licated-in-the-materials-asset-bundle.717833/
     
  9. SuperNbie

    SuperNbie

    Joined:
    Nov 1, 2012
    Posts:
    15
    Hi, MacroPinch

    Thank you for answer.
    I think this is a very important issue for developing a patch system.
    I'm curious if other people have created a patch system without fixing this problem.
     
  10. beatmicro

    beatmicro

    Joined:
    Jun 1, 2021
    Posts:
    1
    I have the same question as you
    finally, i find the problem
    the sprite must texture, instead of sprite, then solve the problem
    because if you set sprite mode, the material dependence the sprite instead of texture,so there have two of it.