You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity2020.3.43+Vuforia10.18.4构建时Reference Rewriter错误求助

问题解决:Unity构建时Vuforia与Texture2D.Reinitialize方法缺失错误

环境信息

  • Unity版本:2020.3.43
  • Vuforia Engine版本:10.18.4
  • MRTK版本:2.8.2.0

问题描述

在MixedRealityToolkit中为Main Camera附加Vuforia Behaviour后,运行时可正常检测图片并显示,但构建时出现重复错误:

Reference Rewriter运行时提示方法System.Boolean UnityEngine.Texture2D::Reinitialize(System.Int32,System.Int32,UnityEngine.TextureFormat,System.Boolean)在目标框架中不存在,该方法由Vuforia.Unity.Engine.dll中的System.Void Vuforia.Image::ResizeTexture(UnityEngine.Texture2D,System.Int32,System.Int32,UnityEngine.TextureFormat)引用。

更换不同Vuforia版本后仍报错。

解决方案

  • 调整API兼容性级别
    打开Unity编辑器,依次进入Edit > Project Settings > Player,在「Other Settings」中找到API Compatibility Level,将其从.NET Standard 2.0切换为.NET 4.x Equivalent。Texture2D.Reinitialize方法在.NET Standard环境下可能被代码裁剪工具移除,.NET 4.x会保留更多Unity原生API。

  • 添加Linker.xml保留目标方法
    在项目Assets目录下创建Linker.xml文件,写入以下内容:

    <linker>
      <assembly fullname="UnityEngine.CoreModule">
        <type fullname="UnityEngine.Texture2D">
          <method name="Reinitialize" signature="System.Boolean Reinitialize(System.Int32,System.Int32,UnityEngine.TextureFormat,System.Boolean)" />
        </type>
      </assembly>
    </linker>
    

    该文件会告知Unity的代码剥离工具不要移除Texture2D.Reinitialize方法,避免Vuforia调用时找不到依赖。

  • 校验MRTK与Vuforia的集成配置

    1. 选中场景中的MixedRealityToolkit对象,打开Inspector面板切换到「Camera」选项卡
    2. 确认Camera Settings Profile中的Background Mode设置为Vuforia,且Vuforia相机提供者已启用
    3. 检查Main Camera是否存在组件冲突,确保MRTK相机组件与Vuforia Behaviour的配置层级不重复
  • 清理缓存重新导入资源

    1. 关闭Unity编辑器
    2. 删除项目目录下的Library和Temp文件夹
    3. 重新打开Unity,等待资源重新导入完成后,重新安装对应版本的Vuforia Engine

内容的提问来源于stack exchange,提问作者JIA RONG WU

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 22:57:15