我创建了一个自定义组件,并确保在实例化使用此组件的实体之前调用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
对象本身上的组件时,仍然看不到该组件。
有了这么少的文档,我似乎找不到我做错了什么。任何帮助将不胜感激。