Unable to build the sample code for WWDC RealityKit 2 session

Hi I'm trying to become familiar with RealityKit 2. I'm trying to build the code in the session, but I'm getting compile errors.

Any advice?

Link to the sample code below

https://developer.apple.com/documentation/realitykit/building_an_immersive_experience_with_realitykit

Accepted Reply

Thanks for your reply. Yes I'm running Xcode 13 beta

Replies

I had no problem building and running. But I have noticed this week that sometimes by default a project intended for iOS 15 Beta and/or Xcode 13.0 Beta may by default open in Xcode 12.5 and I'll get all types of errors until i realize that i'm in the wrong version of Xcode. Now I generally right-click on project files and specific 'open with Xcode-beta'. Are you sure you're opening it up with the correct version?

Thanks for your reply. Yes I'm running Xcode 13 beta

I just built this for Xcode 13.1 by applying the following diffs (make sure you're building for a device, not the simulator - the code doesn't compile for the simulator, which isn't mentioned in the README - FB9181536):

diff --git a/Underwater/Octopus.swift b/Underwater/Octopus.swift
index e447a32..7a99708 100644
--- a/Underwater/Octopus.swift
+++ b/Underwater/Octopus.swift
@@ -82,7 +82,7 @@ struct OctopusSystem: RealityKit.System {
         let scene = context.scene
         for octopus in scene.performQuery(OctopusComponent.query) {
             guard octopus.isEnabled else { continue }
-            guard var component = octopus.components[OctopusComponent] as? OctopusComponent else { continue }
+            guard var component = octopus.components[OctopusComponent.self] as? OctopusComponent else { continue }
             guard component.settings?.octopus.fearsCamera ?? false else { return }
             switch component.state {
             case .hiding:
diff --git a/Underwater/Scattering.swift b/Underwater/Scattering.swift
index 0883bdb..db3aa47 100644
--- a/Underwater/Scattering.swift
+++ b/Underwater/Scattering.swift
@@ -127,8 +127,8 @@ extension Entity {
         if let animation = try? AnimationResource.generate(with: FromToByAnimation<Transform>(
             from: transformWithZeroScale,
             to: transform,
-            duration: 1.0,
-            targetPath: .transform
+            duration: 1.0
+//            targetPath: .transform
         )) {
             playAnimation(animation)
         }