{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict/",
  "atlas": "https://www.pystone.net/?node=uwa-answer-editor-loaded-texture-atlas-conflict#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict.md",
  "context": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:uwa-answer-editor-loaded-texture-atlas-conflict",
  "slug": "uwa-answer-editor-loaded-texture-atlas-conflict",
  "title": "Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "石心.Yong"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误",
  "contentRole": "source",
  "sourceType": "source",
  "sourceMetadata": {
    "author": "石心.Yong"
  },
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "external_source",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "de1881daf12a3f07ab9f2681b9264bcab562586525613f79a6b21f4c8ecca8d9",
  "assets": [
    {
      "reference": "assets/6074fe116bb31032f97912ec/01.png",
      "url": "/media/a127a52bbfbc875b3a70.png",
      "mediaType": "image/png",
      "contentHash": "a127a52bbfbc875b3a70f6828576d2cae6efcef0a0fc8815ad176fc7304c1a31",
      "byteLength": 62269,
      "width": 514,
      "height": 451
    },
    {
      "reference": "assets/6074fe116bb31032f97912ec/02.png",
      "url": "/media/d0a5f7d2c415c47671ca.png",
      "mediaType": "image/png",
      "contentHash": "d0a5f7d2c415c47671ca686aa2d2deead95479d9b43387ddbbdbd29da36ec3e3",
      "byteLength": 102463,
      "width": 1395,
      "height": 516
    },
    {
      "reference": "assets/6074fe116bb31032f97912ec/03.png",
      "url": "/media/a600eb262ecea7c1a9fa.png",
      "mediaType": "image/png",
      "contentHash": "a600eb262ecea7c1a9fa3cd6d246d4f93acabbb120d22aed10f9f9216a678551",
      "byteLength": 15154,
      "width": 528,
      "height": 211
    },
    {
      "reference": "assets/6074fe116bb31032f97912ec/04.png",
      "url": "/media/7d9e9bc9285f7d4a8973.png",
      "mediaType": "image/png",
      "contentHash": "7d9e9bc9285f7d4a89737de7d2aff878b0b9dc2b49668036150dda5a580d11d3",
      "byteLength": 3545,
      "width": 418,
      "height": 67
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误",
      "anchor": "unity-editor模式不运行游戏的情况下内存加载的图片导致游戏图集加载错误",
      "citation": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict/#unity-editor%E6%A8%A1%E5%BC%8F%E4%B8%8D%E8%BF%90%E8%A1%8C%E6%B8%B8%E6%88%8F%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E5%86%85%E5%AD%98%E5%8A%A0%E8%BD%BD%E7%9A%84%E5%9B%BE%E7%89%87%E5%AF%BC%E8%87%B4%E6%B8%B8%E6%88%8F%E5%9B%BE%E9%9B%86%E5%8A%A0%E8%BD%BD%E9%94%99%E8%AF%AF"
    },
    {
      "depth": 2,
      "text": "问题",
      "anchor": "问题",
      "citation": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict/#%E9%97%AE%E9%A2%98"
    },
    {
      "depth": 2,
      "text": "我的回答",
      "anchor": "我的回答",
      "citation": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict/#%E6%88%91%E7%9A%84%E5%9B%9E%E7%AD%94"
    },
    {
      "depth": 2,
      "text": "来源与关系",
      "anchor": "来源与关系",
      "citation": "https://www.pystone.net/notes/uwa-answer-editor-loaded-texture-atlas-conflict/#%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-editor-loaded-texture-atlas-conflict/#%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-14：Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误（项目管理、资源管理、内存管理）",
      "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-14 - Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#%E6%88%91%E7%9A%84uwa%E9%97%AE%E7%AD%94"
    }
  ],
  "contentMarkdown": "# Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误\n\n> [!note] 我的 UWA 问答\n> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。\n\n## 问题\n\nUnity editor模式下编辑prefab，图片会加载到内存中。导致一开始运行游戏的时候会触发相关图集SpriteAtlasManager.atlasRequested的提前调用，导致图集加载错误。\n\n![image.png](assets/6074fe116bb31032f97912ec/01.png)\n\n上图是，过早的图集加载，失败时检测到内存中加载的图片。\n\n有没有办法在运行游戏的时候清除编辑预制体时内存中的图片图集？或者类似的办法？\n\n补充：在不运行游戏的情况下调用内存查看的接口，发现内存中仍然有很多图片被加载了\n\n![image.png](assets/6074fe116bb31032f97912ec/02.png)\n\n- 提问者：潜行医生-577493\n- 提问时间：2021-04-13 18:12:33\n\n## 我的回答\n\n这个问题本质上是，当引用到Atlas的Sprite加载时，如果内存中没有Atlas，就会触发加载图集的”请求“（atlasRequested）。Editor下编辑prefab，会生成这个请求，在游戏运行的第一帧，这个请求函数会被调用。而这个请求是由Native层发出的（[RequiredByNativeCode]），所以我们没有办法控制，跟卸载内存中的资源是没有关系的。\n\n![image.png](assets/6074fe116bb31032f97912ec/03.png)\n\n而这个请求也只会在运行时的第一帧进行调用，所以，不要在第一帧注册atlasRequested事件，在第一帧之后，或者在需要加载相应Prefab时注册该函数，就可以避免在启动游戏时调用该函数。\n\n![image.png](assets/6074fe116bb31032f97912ec/04.png)\n\n- 回答时间：2021-04-14 07:05:16\n- 最后更新：2021-04-14 07:05:16\n- 采纳状态：已采纳\n\n## 来源与关系\n\n- 上位集合：[[10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/我的UWA问答|我的 UWA 问答]]\n- UWA 标签：项目管理、资源管理、内存管理\n- 原始问题：[Unity editor模式不运行游戏的情况下，内存加载的图片导致游戏图集加载错误](https://answer.uwa4d.com/question/6074fe116bb31032f97912ec)\n- 源页最后更新：2021-04-14 07:05:16\n"
}
