Texture share in AssetBundle

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?

5063579–497588–Patch2019.zip (150 KB)

I ran your project, the resulting manifest is this:

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

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?

1 Like

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?

In the project attached above, there are three assets in the BundleAsset folder:

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?

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.

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

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```

[5068460--498188--Patch2019_Prefab.zip|attachment](upload://sTGfg3MD5IBoo3MH6J7qlMr127X.zip) (144 KB)

This may very well be expected behaviour. Have you tried assigning the built in shaders to assetbundles? Download link here https://netstorage.unity3d.com/unity/ebce4d76e6e8/builtin_shaders-2019.2.9f1.zip?_ga=2.158548218.1329062307.1571052789-650627378.1562161922

Some info I found on it here:

Hi,
Your issue looks similar to ours. You can see it here:
https://forum.unity.com/threads/bug-sprite-for-material-is-duplicated-in-the-materials-asset-bundle.717833/

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.

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.