Post

Replies

Boosts

Views

Activity

Reply to Pink Screen with VideoMaterial in ARKit
The following code works on iOS 17 and iPadOS 17.x but not on 18. The Video Plane simply appears pink instead of showing the video itself. import SwiftUI import RealityKit import AVFoundation struct ContentView : View { var body: some View { RealityView { content in // Create a cube model let model = Entity() let mesh = MeshResource.generateBox(size: 0.1, cornerRadius: 0.005) let material = SimpleMaterial(color: .gray, roughness: 0.15, isMetallic: true) model.components.set(ModelComponent(mesh: mesh, materials: [material])) model.position = [0, 0.05, 0] // Create horizontal plane anchor for the content let anchor = AnchorEntity() let player = AVPlayer(url: Bundle.main.url(forResource: "phone-video", withExtension: "mp4")!) let videoMaterial = VideoMaterial(avPlayer: player) let modelEntity = ModelEntity(mesh: .generateBox(width: 2.0, height: 1.7, depth: 0.01), materials: [videoMaterial]) player.play() modelEntity.position.z -= 2 modelEntity.setParent(anchor) anchor.addChild(model) // Add the horizontal plane anchor to the scene content.add(anchor) content.camera = .spatialTracking } .edgesIgnoringSafeArea(.all) } } #Preview { ContentView() }
Topic: Graphics & Games SubTopic: RealityKit Tags:
Apr ’25