没有为组件类型注册存储

时间:2019-11-11 23:57:04

标签: swift arkit realitykit

我创建了一个自定义组件,并确保在实例化使用此组件的实体之前调用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对象本身上的组件时,仍然看不到该组件。

有了这么少的文档,我似乎找不到我做错了什么。任何帮助将不胜感激。

0 个答案:

没有答案