unity build_error ai_generated true

IL2CPP 错误:System.MissingMethodException:找不到方法:'Void UnityEngine.UI.Image::set_sprite(UnityEngine.Sprite)'

IL2CPP error: System.MissingMethodException: Method not found: 'Void UnityEngine.UI.Image::set_sprite(UnityEngine.Sprite)'

ID: unity/il2cpp-missing-method

其他格式: JSON · Markdown 中文 · English
78%修复率
85%置信度
1证据数
2023-08-14首次发现

版本兼容性

版本状态引入弃用备注
2021.3.30f1 active
2022.3.10f1 active
6000.0.0b12 active

根因分析

IL2CPP 代码剥离删除了通过反射或链接器不可见的代码路径引用的方法。

English

IL2CPP code stripping removes a method that is referenced via reflection or a code path not visible to the linker.

generic

官方文档

https://docs.unity3d.com/Manual/IL2CPP-ErrorTroubleshooting.html

解决方案

  1. Add [Preserve] attribute to the specific method: `[Preserve] private void SetSpriteMethod(Sprite s) { image.sprite = s; }`
  2. Create a link.xml file in Assets/Plugins with: <linker><assembly fullname="UnityEngine.UI"><type fullname="UnityEngine.UI.Image" preserve="all"/></assembly></linker>
  3. Use `#if !UNITY_EDITOR` to force a direct call to the method in a startup script so IL2CPP sees it

无效尝试

常见但无效的做法:

  1. 65% 失败

    Preserve only works on specific methods or fields, not entire files; may not cover all reflection paths.

  2. 40% 失败

    Disabling stripping increases build size significantly and may hide but not fix the underlying reflection issue.

  3. 90% 失败

    The issue is in IL2CPP code generation, not asset import; rebuild doesn't change stripping behavior.