我制作了一个自定义组件,并确保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当我在对象本身上的组件时,我仍然收到错误我仍然看不到这个组件。
有了这么少的文档,我似乎找不到我做错了什么。任何帮助,将不胜感激。