I figured out what I was doing wrong. I needed to make a new scene in RCP where the starship is a child to the Earth. The OrbitAnimation struct causes a child entity to orbit around a parent entity. It now works, but I have a lot to fix to make the starship rotate its orientation so the same side always faces the earth and I need to adjust the angle of the orbit and other parameters.
Post
Replies
Boosts
Views
Activity
I've added some of my sample test app code below.
From what I understand, I already have the OrbitAnimation startTransform parameter for my starshipEntity setup correctly based on my Reality Composer Pro (RCP) package that includes the transform component definition for my starship entity (see attached screenshot below for the transform component from RCP). Since I already have my starship and Earth entity defined in my RCP package that I import (i.e. import Starship), I don't believe I need to define the sphere or yAxis property, and my startTransform parameter can just be starshipEntity.transform. I took this code approach based on the WWDC23 session "Build Spatial Experiences with RealityKit" (https://developer.apple.com/wwdc23/10080).
In your example code, you show a translation parameter to the Transform struct. Are you saying there is a translation that needs to be set that is beyond what I already have in the RCP Transform component for my starship entity? If so, I don't understand why and I didn't see something like that needed for the moon entity in the WWDC23 session I reference above. A translation parameter is not mentioned in the above referenced WWDC23 session.
Also, can you confirm that I can do the OrbitAnimation directly in the RealityView content closure and that I don't have to put OrbitAnimation in an update: closure?
import SwiftUI
import RealityKit
import Starship
struct ImmersiveView: View {
@Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace
@Environment(\.dismissWindow) var dismissWindow
@Environment(\.openWindow) var openWindow
var body: some View {
RealityView { content, attachments in
//Get Earth model from createEarthModel() function
let earthEntity = await createEarthModel()
//Get Starship model from createStarshipModel() function
let starshipEntity = await createStarshipModel()
//Add to RealityView
content.add(starshipEntity)
content.add(earthEntity)
//Playing an orbit transform animation
let orbit = OrbitAnimation(name: "Orbit",
duration: 30,
axis: [0, 1, 0],
startTransform: starshipEntity.transform,
bindTarget: .transform,
repeatMode: .repeat)
if let animation = try? AnimationResource.generate(with: orbit) {
starshipEntity.playAnimation(animation)
}
}
}
}
Still not working in iPadOS 18.0 Developer Beta 2.
I've narrowed down the issue further as follows: Reference the FB13917278_Sample_App Xcode project I placed in the feedback running on iPadOS 18.0 Simulator
If I change the SidebarView to make the FunctionView() launch as the detail view, the FunctionView displays correctly and works correctly when the user interacts with the List and children.
However, if I navigate to the StartingView (works ok), then navigate back to the FunctionView, the problem is seen and the FunctionView does not appear.
Therefore, the problem appears to be with the NavigationSplitView and NavigationStack going from another view in the sidebar list to the FunctionView.
When doing step 1 and launching the app I get the following console log messages:
NSBundle file:///Library/Developer/CoreSimulator/Volumes/iOS_22A5282m/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS%2018.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/MetalTools.framework/ principal class is nil because all fallbacks have failed
If I don't interact with the simulator within a few seconds, I get these additional messages:
[C:4-1] Error received: Invalidated by remote connection.
Found no UIEvent for backing event of type: 3; contextId: 0xACBED546
If I interact with the FunctionView list, I get this additional message:
Failed to create 0x88 image slot (alpha=1 wide=1) (client=0xd02d59c7) [0x5 (os/kern) failure]
If I change the SidebarView to back to make the StartingView() launch as the detail view, I get the following console messages upon launch into Portrait orientation:
Failed to send CA Event for app launch measurements for ca_event_type: 0 event_name: com.apple.app_launch_measurement.FirstFramePresentationMetric
Failed to send CA Event for app launch measurements for ca_event_type: 1 event_name: com.apple.app_launch_measurement.ExtendedLaunchMetrics
If I then switch to Landscape orientation, I get the following additional console messages:
[C:4-1] Error received: Invalidated by remote connection.
Found no UIEvent for backing event of type: 3; contextId: 0xD9737857
If I launch into Portrait orientation then immediately switch to Landscape orientation, I get no console messages, but trying to navigate to the FunctionView displays nothing and the app becomes unresponsive.
My production App Store app can be run on iOS/iPadOS 18 Beta. Here is the App Store link:
Starship SE Corps
This plus the provided code excerpts should be sufficient to view the issue in context until I have a chance to try a focused Xcode test project with the risk that a test project doesn’t show the issue like my actual production app does.
Thanks Michael. I appreciate your response. I did have a lab session yesterday and I talked to the engineer about this need that I have per the feedback number. They confirmed it doesn’t appear that there is an ability to do exactly what I want to do as I described in the feedback. I do understand that the accentcolor is deprecated, and the new tint Method is the new way to do things, however I could not get that to work either using foregroundStyle or any method related to tint. I’ll look at your code more and see if I’ve got other ideas based on that.
With accentcolor deprecated, what if I still have an accent color in my assets? That accent color is still being used in my app and other areas and works just fine, just not in the area. Will the accentcolor asset in my app stop working in the future? How does tint now work relative to what I already have defined as an accentcolor in my assets catalog?
I’ll look into this. This might be what I need. For now, I went ahead and submitted a Feedback suggestion:
FB13871808 (Restoring visionOS windows to spatial location upon returning from immersive scene)
Apparently there is a feedback assistant/bug that was mentioned in the Apple Developer Forums. I’ll link below. Currently, when you do the archive build, you have to set the base SDK to visionOS. I did this when I did my separate visionOS build, and it worked fine. Xcode now showing Vision Pro Archive destination.
Answer from other Apple Developer forum post
Thanks so much @gchiste. That was the issue. Now working. It would be nice if the Developer Documentation page Bringing Your Existing Apps to VisionOS could be updated to address this situation more specifically. It vaguely mentions maybe having to adjust build configuration settings but does not address how to do what you show above, which I think would be a fairly common situation for developers converting their existing iOS, iPadOS apps to add visionOS functionality with RCP.
Upon further reading...it appears that the default for Section headers going forward will be to NOT show expansion arrows. To use expansion arrows, a new isExpanded parameter needs to be included in the Section initializer and will be needed to bind to a state property. I haven't gotten this new approach to work, but seems like the answer.
I use to have my Sections (with header) within a List View that was within a NavigationView. Since NavigationView is now deprecated, I've transitioned to using NavigationStack. No other changes to code, but now my section headers don't have a triangle to show/hide the section content...i.e. the section is now longer collapsible. Your code above doesn't show what your ForEach statements are wrapped in. Are they within a List?
I've recently started an app where the content view uses this type of hierarchical list view (with children). I'm able to successfully display the hierarchical list in the content view, and when I tap an item in the hierarchy, I'm successfully able to navigate to a detail view for that tapped item. I'm also able to edit one of the tapped item properties in the detail view using a TextEditor view. However, when I click save in the detail view, the changed property will only be saved if it was the parent list item row that I tapped in the content view. If it was a child list item in the content view, the save does not work. I think I may have a problem in my save code logic and I'm trying to investigate.
I talked with Apple about this during a lab session at WWDC21. They had me create a feedback ticket.
Here is the Feedback:
FB9156589
Apple has some excellent SwiftUI and UIKit tutorials on the developer website. The tutorials allow you to work through the specific app creation projects that teach you the various technologies for SwiftUI and UIKit.
SwiftUI Tutorials
iOS App Dev Tutorials
I'm having a similar problem but with an independent watch app using Swift UI. The live preview in Xcode shows a back button on the detail screen and it allows me to return to the parent (content view) screen. However, when I run the same app on the watch simulator and on an actual Apple Watch Series 6, the back button doesn't appear and I can't navigate back to the parent view.