{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/uwa-answer-unity-world-space-ui-batching-break/",
  "atlas": "https://www.pystone.net/?node=uwa-answer-unity-world-space-ui-batching-break#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/uwa-answer-unity-world-space-ui-batching-break.md",
  "context": "https://www.pystone.net/notes/uwa-answer-unity-world-space-ui-batching-break.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-world-space-ui-batching-break",
  "slug": "uwa-answer-unity-world-space-ui-batching-break",
  "title": "Unity 3D场景UI被打断合批的原因？",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "石心.Yong"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Unity 3D场景UI被打断合批的原因？",
  "contentRole": "source",
  "sourceType": "source",
  "sourceMetadata": {
    "author": "石心.Yong"
  },
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "external_source",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "2f193ba332731c84cc5b3c41a48b3513fbb498d37b0848b23e1e06d49fa8683a",
  "assets": [
    {
      "reference": "assets/606ec4af6bb31032f9791252/01.png",
      "url": "/media/8087e1d4c2df175e0b51.png",
      "mediaType": "image/png",
      "contentHash": "8087e1d4c2df175e0b513bf82afe49a1295aa0a23d57345bb45bc2aab2d3c5c4",
      "byteLength": 236239,
      "width": 2913,
      "height": 1107
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/02.png",
      "url": "/media/d4d3ff72e778a63f80fb.png",
      "mediaType": "image/png",
      "contentHash": "d4d3ff72e778a63f80fbe1210b8186f73be6fd3149622cdabb4cd1d51e103756",
      "byteLength": 98545,
      "width": 1635,
      "height": 811
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/03.png",
      "url": "/media/fe733684a27428c454da.png",
      "mediaType": "image/png",
      "contentHash": "fe733684a27428c454da48cdd8d2349ed2a29666f8196d779879fd28f7ee92bf",
      "byteLength": 6014,
      "width": 246,
      "height": 103
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/04.png",
      "url": "/media/c2be5af13d0a64306eec.png",
      "mediaType": "image/png",
      "contentHash": "c2be5af13d0a64306eecd53998089c62f34a5c0085c852f5e7d2d254d04e62c4",
      "byteLength": 5548,
      "width": 252,
      "height": 91
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/05.png",
      "url": "/media/6d9935f48a475965e4aa.png",
      "mediaType": "image/png",
      "contentHash": "6d9935f48a475965e4aa9166e67f6794f506551985b6fc13c74f20aa4a360a0f",
      "byteLength": 48920,
      "width": 514,
      "height": 423
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/06.png",
      "url": "/media/4b6681be5ac8ebbbc4d9.png",
      "mediaType": "image/png",
      "contentHash": "4b6681be5ac8ebbbc4d93e350823e007811243affa7386a6f93ed2ece9d821d0",
      "byteLength": 7802,
      "width": 500,
      "height": 104
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/07.png",
      "url": "/media/668b669dffcd43971dff.png",
      "mediaType": "image/png",
      "contentHash": "668b669dffcd43971dffc6dc1424ba1b0c988caf0ab5d853dd2256b8d555d024",
      "byteLength": 131278,
      "width": 753,
      "height": 334
    },
    {
      "reference": "assets/606ec4af6bb31032f9791252/08.png",
      "url": "/media/2a46186bd2b02399b90a.png",
      "mediaType": "image/png",
      "contentHash": "2a46186bd2b02399b90af3dce43e725214a27c01e3d5eff9fd00ee82f4a39908",
      "byteLength": 148522,
      "width": 803,
      "height": 248
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "Unity 3D场景UI被打断合批的原因？",
      "anchor": "unity-3d场景ui被打断合批的原因",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-world-space-ui-batching-break/#unity-3d%E5%9C%BA%E6%99%AFui%E8%A2%AB%E6%89%93%E6%96%AD%E5%90%88%E6%89%B9%E7%9A%84%E5%8E%9F%E5%9B%A0"
    },
    {
      "depth": 2,
      "text": "问题",
      "anchor": "问题",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-world-space-ui-batching-break/#%E9%97%AE%E9%A2%98"
    },
    {
      "depth": 2,
      "text": "我的回答",
      "anchor": "我的回答",
      "citation": "https://www.pystone.net/notes/uwa-answer-unity-world-space-ui-batching-break/#%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-world-space-ui-batching-break/#%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-world-space-ui-batching-break/#%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-04-09：Unity 3D场景UI被打断合批的原因？（UI、渲染模块）",
      "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-04-09 - Unity 3D场景UI被打断合批的原因？”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#%E6%88%91%E7%9A%84uwa%E9%97%AE%E7%AD%94"
    }
  ],
  "contentMarkdown": "# Unity 3D场景UI被打断合批的原因？\n\n> [!note] 我的 UWA 问答\n> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。\n\n## 问题\n\n![动态合批被打断.png](assets/606ec4af6bb31032f9791252/01.png)\n\n![动态合批被打断2.png](assets/606ec4af6bb31032f9791252/02.png)\n\n如上图，使用SpriteRenderer做图片和TextMeshPro做文字，使用unity帧调试器查看，发现第一排三个图片动态合批了，第二排三个图片动态合批了，第三排三个图片动态合批了，然后文字都合不了批，原因是动态批处理在player Settings 中被关闭或在当前环境中被暂时禁用，以避免z-fighting。能不能所有图片一个批次，所有文字一个批次，该怎么做？\n\n- 提问者：cwf\n- 提问时间：2021-04-09 00:54:07\n\n## 我的回答\n\n1. 对于普通的Mesh物体的绘制，也就是使用MeshRenderer绘制的Mesh：在开启了动态合批的情况下，使用相同Material的两个物体，以相邻顺序绘制时，如果满足其他动态合批的条件，即可合批。\n\n题主的文字部分没有合批，是因为没有开启动态合批。看FrameDebugger，题主的渲染管线使用的是SRP，开启动态合批的方式是在RenderPipelineAsset的Inspector面板的Advanced下勾选Dynamic Batching。\n\n![image.png](assets/606ec4af6bb31032f9791252/03.png)\n\n至于说为什么图片出现了合批现象，这是因为图片使用SpriteRenderer来绘制，其网格是Unity动态生成的，合批的行为也是Unity内部处理的，不受Dynamic Batching开启与否的影响。\n\n1. 其次是控制渲染顺序，使应该合批的物体以相邻顺序渲染，先绘制所有图片，再绘制所有文字。\n\n方法一：按照楼上说的，设置Order in Layer，图片的Order in Layer设置为0，文字为1。\n\n![image.png](assets/606ec4af6bb31032f9791252/04.png)\n\n方法二：将所有图片的RenderQueue都设置为3000，将所有文字的Render Queue都设置为3001。\n\n![image.png](assets/606ec4af6bb31032f9791252/05.png)\n\n![image.png](assets/606ec4af6bb31032f9791252/06.png)\n\n效果如下：\n\n![image.png](assets/606ec4af6bb31032f9791252/07.png)\n\n![image.png](assets/606ec4af6bb31032f9791252/08.png)\n\n- 回答时间：2021-04-09 21:10:00\n- 最后更新：2021-04-09 21:10:00\n- 采纳状态：已采纳\n\n## 来源与关系\n\n- 上位集合：[[10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/我的UWA问答|我的 UWA 问答]]\n- UWA 标签：UI、渲染模块\n- 原始问题：[Unity 3D场景UI被打断合批的原因？](https://answer.uwa4d.com/question/606ec4af6bb31032f9791252)\n- 源页最后更新：2021-04-09 21:10:00\n"
}
