# MissingReferenceException：精灵 'ui_button_bg' 已被销毁，但你仍在尝试访问它。你的脚本应检查它是否为空，或者你不应销毁该对象。

- **ID:** `unity/missingreferenceexception-ui-image-sprite`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

UI Image 组件的精灵引用指向了一个已被销毁的 Sprite 对象（例如通过 Resources.UnloadUnusedAssets 或场景卸载），而 Image 仍然存在。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2022.3.18f1 | active | — | — |
| Unity 2023.1.5f1 | active | — | — |
| Unity 2021.3.33f1 | active | — | — |

## 解决方案

1. ```
   Before accessing the sprite, check if the Image component's sprite is null and reassign it from a persistent source (e.g., Resources.Load or Addressables).
   ```
2. ```
   Ensure the sprite asset is marked as 'Keep' in the Addressables system or is included in a preloaded asset bundle to prevent it from being unloaded.
   ```

## 无效尝试

- **** — The sprite reference is lost at runtime due to destruction, not because it was never assigned. Setting null prevents the error but breaks UI functionality. (70% 失败率)
- **** — This actually causes the problem; it destroys sprites that are still referenced. (95% 失败率)
- **** — Sprites are not GameObjects; DontDestroyOnLoad works on GameObjects, not assets. (90% 失败率)
