• Runtimes
  • duplicate mesh in bundle when use nested prefab (Unity)

unity: 2021.3.21f1
spine runtime: spine-unity-4.2-2025-03-24

there are 3 prefab, nested

pack prefab_3 in one bundle, will find 3 Mesh assets in bundle

Related Discussions
...
  • Đã chỉnh sửa

The issue you're experiencing with duplicate mesh assets in your Unity bundle when using nested prefabs is related to how the spine-unity runtime handles mesh data. In spine-unity 4.0 and later, the generated skeleton mesh is added to the prefab to provide preview images and thumbnails in the Unity Editor. This can lead to multiple instances of the mesh being included in the bundle if the prefabs are nested. To address this, you can configure the behavior via the Unity Preferences under Edit - Preferences - Spine, specifically in the Prefabs section. Additionally, ensure that the meshes are automatically removed before building the executable via a pre-build step, which should prevent them from increasing the build size or load time.

For more detailed information, you can refer to the Spine Preferences documentation and the related GitHub issue.

  • Harald đã trả lời bài viết này.

    Spinebot Additionally, ensure that the meshes are automatically removed before building the executable via a pre-build step, which should prevent them from increasing the build size or load time.

    To remove prefab meshes, enable Optimize Preview Meshes in the Prefabs section in the Spine Preferences. Then when building the asset bundles during the game build, the prefab meshes are removed at the start of the procedure.

    @wulilio Note that when building asset bundles via e.g. the Addressable Groups window, these pre- and post-build steps are not executed. Unfortunately Unity does not provide a build callback for asset bundles or addressables like BuildPlayerProcessor does for player builds. You could however write your own build scripts which first remove the prefab meshes and then build your addressable packs.

    The relevant code can be found here:
    PreprocessSpinePrefabMeshes():
    EsotericSoftware/spine-runtimesblob/4.2/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs#L100

    PostprocessSpinePrefabMeshes():
    EsotericSoftware/spine-runtimesblob/4.2/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs#L129