当前位置: 首页 > news >正文

【Unity实战|热更】Addressable读取SO文件报错解决

情景再现

假定你有一个Unity工程,使用了HybridCLR和Addressable,SO文件存放在Addressable中。热更加载后进入游戏场景出现了SO文件读取报错:

UnityEngine.AddressableAssets.InvalidKeyException: Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown. No Asset found with for Key=Inventory Model Database. Key exists as Type=System.Object, which is not assignable from the requested Type=InventorySystem.Models.InventoryModelDatabase
UnityEngine.AddressableAssets.Addressables:LoadAssetAsync(Object)

可能原因

读取SO文件时,文件绑定的脚本并没有成功还原出来。见官方文档。

解决办法

加载SO文件的代码时不要声明具体的类型,改用System.Object,成功后进行强转。

Before:

Addressables.LoadAssetAsync<InventoryModelDatabase>("Inventory Model Database").Completed += handle =>{if (handle.Status == AsyncOperationStatus.Succeeded){_inventoryModelDatabase = handle.Result;Debug.Log($"[{GetType()}] Inventory Model Database loaded!");}elseDebug.LogError($"[{GetType()}] Failed to load Inventory Model Database!");};

After:

Addressables.LoadAssetAsync<System.Object>("Inventory Model Database").Completed += handle =>{if (handle.Status == AsyncOperationStatus.Succeeded){_inventoryModelDatabase = handle.Result as InventoryModelDatabase;Debug.Log($"[{GetType()}] Inventory Model Database loaded!");}elseDebug.LogError($"[{GetType()}] Failed to load Inventory Model Database!");};

问题解决。

http://www.lryc.cn/news/347669.html

相关文章:

  • Web自动化 - selenium
  • 基于select for update 实现数据库分布式锁
  • Java后端实现对象与文件接收数据(minio测试)
  • 考研踩坑经验分享
  • Android Compose 一:基础控件
  • python3.12.0 在Linux 制作镜像包 部署到docker 全过程
  • STM32理论 —— μCOS-Ⅲ(新)
  • 衢州知识付费系统报价,教师如何做精品课程?怎么创造精品课程?
  • 在Vue中,可以通过使用<slot>元素和name属性来创建具名插槽。这样您就可以为一个组件的不同部分定义不同的内容。 以下是一个简单的示例:
  • C++笔试强训day19
  • MySQL软件安装基于压缩包
  • 04 贝尔曼最优公式
  • 印象笔记使用技巧
  • 产品设计中的“注册”说明
  • 【linux学习】多线程(1)
  • Leetcode 3149. Find the Minimum Cost Array Permutation
  • Python | 为列表中的元素分配唯一值
  • HTML炫酷的相册
  • C++笔试强训day20
  • 【PHP【实战项目】系统性教学】——使用最精简的代码完成用户的登录与退出
  • Linux下的常用基本指令
  • phpstorm环境配置与应用
  • 【Qt 学习笔记】Qt常用控件 | 布局管理器 | 水平布局Horizontal Layout
  • Hive Aggregation 聚合函数
  • Unity 性能优化之GPU Instancing(五)
  • LeetCode 138. 随机链表的复制
  • 【PC微信小程序点不动处理方法】
  • 量化交易:日内网格交易策略.md
  • Ubuntu 20.04在Anaconda虚拟环境中配置PyQt4
  • charts3D地球--添加航线