Reality View argument type does not conform to protocol view

I'm working on creating a panorama view in AVP. When I got to this line of code Xcode says that "Type 'Entity' does not conform to protocol 'View'": private var realityView: RealityView<Entity>! as well as this line, with the same error message: private func setupPanoramaScene(for content: RealityView<Entity>.Content)

What should I put as a argument for reality view? It doesn't work without arguments either.

Answered by Vision Pro Engineer in 821341022

Hey @Sophiab20,

It's hard to understand what exactly your issue is with the limited code snippets provided. It looks like you're having trouble passing around the RealityKitContent object. You initialize a RealityView with a closure that adds entities to the RealityKitContent object. Simulating particles in your visionOS app provides an example of passing around the content variable using the following:

RealityView { content in
    buildEmitterContent(content, with: geometry.size.vector)
}

func buildEmitterContent(_ content: RealityViewContent, with geometryVector: SIMD3<Double>) {}

Let me know if this helps. If this doesn't help solve your issue could you provide more information as to what you are doing.

Thanks,
Michael

Hey @Sophiab20,

It's hard to understand what exactly your issue is with the limited code snippets provided. It looks like you're having trouble passing around the RealityKitContent object. You initialize a RealityView with a closure that adds entities to the RealityKitContent object. Simulating particles in your visionOS app provides an example of passing around the content variable using the following:

RealityView { content in
    buildEmitterContent(content, with: geometry.size.vector)
}

func buildEmitterContent(_ content: RealityViewContent, with geometryVector: SIMD3<Double>) {}

Let me know if this helps. If this doesn't help solve your issue could you provide more information as to what you are doing.

Thanks,
Michael

Hi Michael, Thank you so mich for your responce! The probem seemes to be on the 6th and the setupPanoramaScene fuction lines. Here is the full snipppet of code:

class PanoramaPlayerController: UIViewController {
    private let videoURL: URL
    private var videoPlayer: AVPlayer!
    private var videoNode: ModelEntity!
    private var anchorEntity: AnchorEntity!
    private var realityView: RealityView<Entity>!
    var gestureDelegate: GestureDelegate?

    init(videoURL: URL) {
        self.videoURL = videoURL
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Create RealityView
        realityView = RealityView { content in
            self.setupPanoramaScene(for: content)
        }

        view.addSubview(realityView)
        realityView.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            realityView.topAnchor.constraint(equalTo: view.topAnchor),
            realityView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            realityView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            realityView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
        ])

        setupGestureRecognition()
    }

    private func setupPanoramaScene(for content: RealityView<Entity>.Content) {
        let sphere = MeshResource.generateSphere(radius: 10)
        videoPlayer = AVPlayer(url: videoURL)
        let material = VideoMaterial(avPlayer: videoPlayer)

        videoNode = ModelEntity(mesh: sphere, materials: [material])
        videoNode.transform = Transform(pitch: .pi / 2, yaw: 0, roll: 0)

        anchorEntity = AnchorEntity(world: .zero)
        anchorEntity.addChild(videoNode)

        content.add(anchorEntity)
        videoPlayer.play()
    }

Hey @Sophiab20,

I noticed that you are using UIKit for your application. Although it's possible to mix SwiftUI and UIKit, visionOS works best with SwiftUI based applications. Please read the Consider your implementation section for more advice on using UIKit on visionOS. If this is a new application, please start with SwiftUI.

As stated previously, your setupPanoramaScene function should accept the RealityViewContent type. If you change the method definition to func setupPanoramaScene(for content: RealityViewContent) this line will compile.

Additionally, if you'd like to include a SwiftUI view like RealityView inside of your UIKit view hierarchy you will need to use a UIHostingController.

I would not recommend this, but you could update your realityView to be of UIViewController and set it using the following:

realityViewHostingController = UIHostingController(rootView: RealityView { content in
    self.setupPanoramaScene(for: content)
})

Thanks,
Michael

Reality View argument type does not conform to protocol view
 
 
Q