swift - 没有为组件类型注册存储
问题描述
我制作了一个自定义组件,并确保registerComponent()
在实例化使用该组件的实体之前调用。
即使在使用前注册了我的组件后,我仍然收到一个EXC_BAD_ACCESS
旧的
“没有为组件类型 3445452219525568944(ARSDKPrototypePlatform.ManagedARObjectComponent) 注册存储”错误
我有一个组件和协议
struct ManagedARObjectComponent: Component, Codable, Equatable {
var isDeployed = false
var id: Int
public static func == (lhs: ManagedARObjectComponent, rhs: ManagedARObjectComponent) -> Bool {
return lhs.id == rhs.id
}
}
protocol HasManagement {
var managedObject: ManagedARObjectComponent { get set }
}
当我实例化 ARView 时,我注册了这个组件
func makeUIView(context: Context) -> ARView {
let arView = sessionDelegate.arView
// Configure the AR session for horizontal plane tracking.
let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = .horizontal
arView.session.run(arConfiguration)
ManagedARObjectComponent.registerComponent()
return arView
}
我有一个符合HasManagement
协议的类
class AREntity: Entity, HasModel, HasCollision, HasAnchoring, HasManagement {
var managedObject: ManagedARObjectComponent {
get { components[ManagedARObjectComponent] ?? ManagedARObjectComponent(id: -1) }
set { components[ManagedARObjectComponent] = newValue }
}
init(id: Int) {
super.init()
self.managedObject = ManagedARObjectComponent(id: id)
// ... more initialization code
}
}
我尝试在我第一次实例化的函数中注册它AREntity
@discardableResult
func generateBox() -> AREntity {
ManagedARObjectComponent.self.registerComponent()
let entity = AREntity(id: UUID().hashValue)
arView.scene.addAnchor(entity)
return entity
}
po
当我在对象本身上的组件时,我仍然收到错误我仍然看不到这个组件。
有了这么少的文档,我似乎找不到我做错了什么。任何帮助,将不胜感激。
解决方案
推荐阅读
- c# - 大小图像与自身背后/下方的图像成比例?
- file - 新手尝试使用外置硬盘在设备之间移动
- openxml - 接受插入拒绝删除openxml
- sql-server - 注销服务器时部署到 Powerbi 报告服务器故障的 Powershell
- sql - 在 SQL 查询中将多个不同的值组合在一起
- python - 正则表达式在 JS 对象中找到匹配项
- python - 将元素添加到 np 数组然后快速排序?或者找到一种方法将其插入到位,python 和 np 数组
- python - 当输出正常时,Tensorflow 总是给我相同的结果
- javascript - 在 iOS 上反应控制的输入行为不正确
- node.js - 创建新元素时,我的 foreignKey 始终为空。续集,节点,Postgresql