{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy/",
  "atlas": "https://www.pystone.net/?node=uwa-answer-unity-material-texture-redundancy#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy.md",
  "context": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:uwa-answer-unity-material-texture-redundancy",
  "slug": "uwa-answer-unity-material-texture-redundancy",
  "title": "Unity2018.4上材质对贴图的冗余引用是否可以不管？",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "石心.Yong"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Unity2018.4上材质对贴图的冗余引用是否可以不管？",
  "contentRole": "source",
  "sourceType": "source",
  "sourceMetadata": {
    "author": "石心.Yong"
  },
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "external_source",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "438273b5b570934bc4c2277a50ae6b37d4f2d6950faaad1b55ecf6b64d950678",
  "assets": [
    {
      "reference": "assets/60a65af06bb31032f9791779/01.png",
      "url": "/media/af4668b6c676974b568b.png",
      "mediaType": "image/png",
      "contentHash": "af4668b6c676974b568b831b278b8c29a8c622e7bd2795bd565928d8c234bf29",
      "byteLength": 43621,
      "width": 828,
      "height": 529
    },
    {
      "reference": "assets/60a65af06bb31032f9791779/02.png",
      "url": "/media/9786db4856c56b38136c.png",
      "mediaType": "image/png",
      "contentHash": "9786db4856c56b38136c7edfba1021d5e01d0b7f893d87fce41a429c59b2d7dc",
      "byteLength": 2685,
      "width": 281,
      "height": 73
    },
    {
      "reference": "assets/60a65af06bb31032f9791779/03.png",
      "url": "/media/65f06cc14a00037f778e.png",
      "mediaType": "image/png",
      "contentHash": "65f06cc14a00037f778e416dc63a2b5f4c7b82b02ef266513a3b6988b2034623",
      "byteLength": 4710,
      "width": 120,
      "height": 76
    },
    {
      "reference": "assets/60a65af06bb31032f9791779/04.png",
      "url": "/media/10647b512d5957a44cd0.png",
      "mediaType": "image/png",
      "contentHash": "10647b512d5957a44cd001fcfab4090ffdcc3a274aff868ec824032503b31e55",
      "byteLength": 12989,
      "width": 577,
      "height": 101
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "Unity2018.4上材质对贴图的冗余引用是否可以不管？",
      "anchor": "unity20184上材质对贴图的冗余引用是否可以不管",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy/#unity20184%E4%B8%8A%E6%9D%90%E8%B4%A8%E5%AF%B9%E8%B4%B4%E5%9B%BE%E7%9A%84%E5%86%97%E4%BD%99%E5%BC%95%E7%94%A8%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E4%B8%8D%E7%AE%A1"
    },
    {
      "depth": 2,
      "text": "问题",
      "anchor": "问题",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy/#%E9%97%AE%E9%A2%98"
    },
    {
      "depth": 2,
      "text": "我的回答",
      "anchor": "我的回答",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy/#%E6%88%91%E7%9A%84%E5%9B%9E%E7%AD%94"
    },
    {
      "depth": 2,
      "text": "来源与关系",
      "anchor": "来源与关系",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy/#%E6%9D%A5%E6%BA%90%E4%B8%8E%E5%85%B3%E7%B3%BB"
    }
  ],
  "claims": [],
  "outgoing": [
    {
      "id": "note:my-uwa-answers",
      "title": "我的 UWA 问答",
      "url": "https://www.pystone.net/notes/my-uwa-answers/",
      "atlas": "https://www.pystone.net/?node=my-uwa-answers#knowledge-atlas",
      "label": "我的 UWA 问答",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "上位集合：我的 UWA 问答",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-material-texture-redundancy/#%E6%9D%A5%E6%BA%90%E4%B8%8E%E5%85%B3%E7%B3%BB"
    }
  ],
  "incoming": [
    {
      "id": "note:my-uwa-answers",
      "title": "我的 UWA 问答",
      "url": "https://www.pystone.net/notes/my-uwa-answers/",
      "atlas": "https://www.pystone.net/?node=my-uwa-answers#knowledge-atlas",
      "label": "我的 UWA 问答",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "2021-05-21：Unity2018.4上材质对贴图的冗余引用是否可以不管？（Shader、资源管理、渲染模块）",
      "citation": "https://www.pystone.net/notes/my-uwa-answers/#2021"
    },
    {
      "id": "note:game-graphics-and-runtime",
      "title": "游戏图形与运行时",
      "url": "https://www.pystone.net/notes/game-graphics-and-runtime/",
      "atlas": "https://www.pystone.net/?node=game-graphics-and-runtime#knowledge-atlas",
      "label": "游戏图形与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "我的UWA问答中的“2021-05-21 - Unity2018.4上材质对贴图的冗余引用是否可以不管？”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#%E6%88%91%E7%9A%84uwa%E9%97%AE%E7%AD%94"
    }
  ],
  "contentMarkdown": "# Unity2018.4上材质对贴图的冗余引用是否可以不管？\n\n> [!note] 我的 UWA 问答\n> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。\n\n## 问题\n\n打包后使用AssetHunter插件分析发现有很多冗余引用，但是在游戏中使用Profiler却没有\n\n打开材质文件发现保存了很多旧的贴图引用信息\n\n![image.png](assets/60a65af06bb31032f9791779/01.png)\n\n如_CloudTex这个，是旧版本使用过的，新的Shader里都没有这个属性了\n\n一般的查找引用的方法是找到所有关联的GUID，那就会找到这些旧的引用\n\n但在手机上使用Profiler看内存时却没有相关引用的贴图被加载\n\n所以是否是因为Unity打包时会自动把这些旧引用筛除？尽管在Editor上还是找得到这些冗余引用，是否可以不用理会？\n\n- 提问者：wenzhao\n- 提问时间：2021-05-21 04:49:52\n\n## 我的回答\n\n旧的Shader使用过的texture引用会被保留在序列化信息中，这是Unity有意的设计，为了避免编辑器下切换Shader再换回来时需要重新配置的麻烦。\n\n而Unity在**打包时确实会对材质进行深度检查，把当前Shader没有使用的texture依赖都去除**，因此通常情况下打包旧的引用也不会导致包体变大。\n\n但旧的引用在Editor下还存在一个问题，AssetDatabase.GetDependencies接口返回的引用会包括旧的引用，它不会进行深度检测来进行剔除。右键资源Select Dependencies调用的是这个接口，所以也会显示旧的引用，如下图：\n\n![image.png](assets/60a65af06bb31032f9791779/02.png)\n\npic2和pic3是当前Shader2没有引用的。\n\n![image.png](assets/60a65af06bb31032f9791779/03.png)\n\n所以使用GetDependencies这个接口实现一些功能的话，可能由于旧引用导致意外的问题。解决方法是，使用EditorUtility.CollectDependencies这个接口可以返回剔除旧引用的结果。\n\n此外，如果Mat和Pic1，Pic2，Pic3分配别单独打了一个AB包，那么打出的mat.manifest文件中会显示旧的Texture引用，这就是AssetBundle打包的一个不太合理的地方了，还没有调研新的Addressable系统是否做了改进。\n\n![image.png](assets/60a65af06bb31032f9791779/04.png)\n\n- 回答时间：2021-05-21 20:01:18\n- 最后更新：2021-05-21 20:01:18\n- 采纳状态：未采纳\n\n## 来源与关系\n\n- 上位集合：[[10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/我的UWA问答|我的 UWA 问答]]\n- UWA 标签：Shader、资源管理、渲染模块\n- 原始问题：[Unity2018.4上材质对贴图的冗余引用是否可以不管？](https://answer.uwa4d.com/question/60a65af06bb31032f9791779)\n- 源页最后更新：2021-05-23 23:23:03\n"
}
