When I run my visionOS App, RealityKitContent Report an error:
Tool terminated by signal 'Segmentation fault: 11'
And it points to a USDZ model I imported, but in the scene, my model can be displayed normally and there is no damage. Why does an error occur? How can I check and repair it?
RealityKit
RSS for tagSimulate and render 3D content for use in your augmented reality apps using RealityKit.
Posts under RealityKit tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
How to overlay an image in RealityKit on a 3D model using code so that it does not stretch to the entire object, but has its own height and width that I can change?
I have a solution on how to do this, but then it will not be possible to change the height, width or place it anywhere on the 3D model. And this is to cut out a part of the object and overlay the image on the entire cutout area. How to overlay a 2D image on a 3D model without stretching the photo to the entire 3D object?
If this is possible, please give an example of how to do this in code. I could not find on the Internet how to do this. Although in other engines this can be done, for example, in Blender or Unity. If I am not mistaken, this is done there using decals
Can anyone provide or point me to example code to fade in / out spotlights over 1 second?
Did not find anything on this topic in the docs:
https://developer.apple.com/documentation/realitykit/spotlight
I'm using Reality Composer Pro Version 2.0 Version 2.0 (448.0.10.0.2) avaliable in Xcode_16_beta_4
When adding a animation from the Animation Library component on my armature to a timeline - the animation does not 'freeze' on the last frame.
Is there a way to 'freeze' the first or last frames when adding animations to the timeline? And how should I expect the first and last keys on my animations to behave with the default 'rest pose' on the imported usd file?
Hello, I was wondering how I can initialize an ImageAnchoringSource using
https://developer.apple.com/documentation/realitykit/anchoringcomponent/imageanchoringsource/init(_:)
When I construct one using a URL, it doesn't seem to be tracked and I see in the following when I debug print the component:
▿ 0 : AnchoringComponent
▿ target : Target
▿ referenceImage : 1 element
▿ from : ImageAnchoringSource
▿ url : Optional<URL>
▿ some : file:///var/mobile/Containers/Data/Application/D1126EA0-A1D7-468F-A40C-8578B7F5BDDF/Library/Caches/CodeCache/0E457AA7-2195-48B9-9DD4-58CEB9397F69.png
- _url : file:///var/mobile/Containers/Data/Application/D1126EA0-A1D7-468F-A40C-8578B7F5BDDF/Library/Caches/CodeCache/0E457AA7-2195-48B9-9DD4-58CEB9397F69.png
- _parseInfo : nil
- _baseParseInfo : nil
- name : nil
- group : nil
▿ trackingMode : TrackingMode
- trackingMode : 2
Is there a specific format for the parseInfo?
When I use the same image to make an image anchoring source by group and name in AR Resources, it is tracked.
Thank you!
I noticed that with the 4th betas of iOS 18 and visionOS 2, some USDZ models' texture mapping looks completely broken. The issue occurs only with a device, not with the Simulator. It's a regression, the models look fine with iOS 17.5.1 and visionOS 1.2.
The issue occurs if I load a model as an Entity in a RealityView iOS or visionOS, or in a SwiftUI 3DModel view on visionOS.
Has anyone seen this too? Is there a workaround?
I filed a bug report with a minimal example project, it's FB14473756.
Screenshot on Vision Pro device:
Screenshot on Vision Pro Simulator:
Has anyone gotten EnvironmentLightingConfigurationComponent to work?
I tried the code from https://developer.apple.com/documentation/realitykit/environmentlightingconfigurationcomponent to prevent a planet from being lit by the environment. My goal is that the side that isn't lit by the star appears pitch black. However, the code seems to have no effect on visionOS 2 and iPadOS 18 (I tried betas 1 through 4, on device, built with Xcode 16 beta 4).
No matter if there is a PointLight or no light at all in the scene, no matter if I use SimpleMaterial or PhysicallyBasedMaterial, no matter if I use a texture or a color on the sphere.
I filed a bug report, it's FB14470954.
Or am I doing something wrong? Here's my code:
var material = PhysicallyBasedMaterial()
if let tex = try? await TextureResource(named: "planet.jpg")
{
material.baseColor = .init(texture: .init(tex))
material.emissiveIntensity = 0
let sphereMesh = MeshResource.generateSphere(radius: 0.5)
let entity = ModelEntity()
entity.components.set(ModelComponent(mesh: sphereMesh, materials: [material]))
entity.position = [-1, 1.0, -1.0]
let envLightingConfig = EnvironmentLightingConfigurationComponent(environmentLightingWeight: 0)
entity.components.set(envLightingConfig)
content.add(entity)
}
Hi I am using this function to create collisions in my scene from Apple Developer Video I found.
func processReconstructionUpdates() async {
for await update in sceneReconstruction.anchorUpdates {
let meshAnchor = update.anchor
guard let shape = try? await ShapeResource.generateStaticMesh(from: meshAnchor)
else {continue}
switch update.event {
case .added:
let entity = ModelEntity()
entity.transform = Transform(matrix: meshAnchor.originFromAnchorTransform)
entity.collision = CollisionComponent(shapes: [shape], isStatic: true)
entity.physicsBody = PhysicsBodyComponent()
entity.components.set(InputTargetComponent())
meshEntities[meshAnchor.id] = entity
contentEntity.addChild(entity)
case .updated:
guard let entity = meshEntities[meshAnchor.id] else { fatalError("...") }
entity.transform = Transform(matrix: meshAnchor.originFromAnchorTransform)
entity.collision?.shapes = [shape]
case .removed:
meshEntities[meshAnchor.id]?.removeFromParent()
meshEntities.removeValue(forKey: meshAnchor.id)
}
}
}
The code works great.
In the same immersive space I am opening a window:
var body: some View {
RealityView { content in
// some other code here
openWindow(id: "mywindowidhere")
// some other code here
}
}
The window opens in front of me, but I am not able to click or even hover on the buttons.
At first I did not know why that was happening. But then I turned on pointer control and found out that the pointer is actually colliding with the wall. (the window is kinda inside the wall). That is why the pointer never reaches the window and the button never gets clicked.
I initially thought this was a layering issue, but I was not able to find any documentation related to this.
Is this a known issue and is there any way to fix this? Or I am doing anything wrong on my side?
I'm following WWDC for interactive 3D content in reality composer pro and apple's document
https://developer.apple.com/wwdc24/10102
https://developer.apple.com/documentation/realitykit/implementing-systems-for-entities-in-a-scene#Retrieve-entities-with-an-entity-query
However, this simple code to declare a dummy Component and System has compile error
/Users/Workspaces/repository/Packages/RealityKitContent/Sources/RealityKitContent/RobotComponent.swift:18:24 Static property 'query' is not concurrency-safe because non-'Sendable' type 'EntityQuery' may have shared mutable state
// Define a query to return all entities with a MyComponent.
private static let query = EntityQuery(where: .has(MyComponent.self))
// Initializer is required. Use an empty implementation if there's no setup needed.
required init(scene: Scene) { }
// Iterate through all entities containing a MyComponent.
func update(context: SceneUpdateContext) {
for entity in context.entities(
matching: Self.query,
updatingSystemWhen: .rendering
) {
// Make per-update changes to each entity here.
}
}
}
I'm using XCode beta3 and project target visionos 2
Does visionOS 2 still prompt the user with a permission alert when a full immersive space is presented?
In visionOS 1, the first time an app presented an immersive space, the user was prompted with an alert to grant permission. openImmersiveSpace would return an error code if the user opted not to grant permission. In visionOS 1, it was important to handle this case correctly.
In visionOS 1, the Settings > Developer menu had an option to reset the immersive user's space permission prompting state so developers could test this interaction flow.
In visionOS 2, I no longer see the full immersive space permissions alert. I can't remember if I saw it once, the first time visionOS 2.0 beta was installed, or if I never saw it at all. The Settings > Developer menu no longer has an option to reset the permission prompting state. I can't find any way to test the interaction flow in my app to make sure that it will work correctly for users.
Does visionOS 2 no longer ask for full immersive space permission at all? I can't find this change documented anywhere.
If visionOS 2 does prompt the user for permission, is there any way to reproduce and test this interaction flow so I can make sure my app handles it correctly?
Thanks for taking the time to answer this question.
I'm playing with visionOS and trying to get a usdz file to load in a RealityView. It works fine if I use a Model3D but if I use a RealityView nothing shows up. I'm just using the fender_stratocaster asset right off the apple web site so it seems like it should work. This is the code:
RealityView { content in
if let sphereEntity = try? await Entity(named: "fender_stratocaster") {
content.add(sphereEntity)
sphereEntity.position = [0,0,0]
sphereEntity.transform.scale = [scale, scale, scale]
let _ = print(sphereEntity)
}
} update: { content in
if let sphereEntity = content.entities.first {
sphereEntity.transform.scale = [scale, scale, scale]
}
Any clues as to why this is not showing would be appreciated.
Given that one can add custom components and expose them via RCP, how do I go about implementing my components / system in a way where when I make a parameter change that gets applied to the entitiy in the RCP viewport?
I have an Entity exported from Blender, after loaded from RealityView, the "Body" and "Mesh" Entity have no ModelComponent, but they have Material Bindings reference, how can I update their materials?
I am trying to add joints via code in my visionOS app. My scenario requires me to combine models from Reality Composer Pro with entities and components from code to generate the dynamic result.
I am using the latest visionOS beta and Xcode versions and there is no documentation about joints. I tried to add them via the available API but regardless of how I combine pins, joints and various component, my entities will not get restricted or stay fixated like they are when they are in a child/parent relationship.
I am using RealityKit and RealityView in mixed mode. I also searched the whole internet for related information without finding anything.
Any insights or pointers appreciated!
If I attach my swiftui view via an ViewAttachmentEntity it will show the view but any ornaments defined are not showing up at all. When I use Xcode preview on the swiftui view the ornaments show up correctly. I am using visionOS beta 3 and the problem easy to reproduce.
Are ornaments on views supported if the view is displayed via an ViewAttachmentEntity?
What’s the difference between an action and an animation eg.: FromToByAnimation vs FromToByAction.
The documentation on them is pretty similar and I'm not understanding the differences exactly... : S
FromToByAnimation → https://developer.apple.com/documentation/realitykit/fromtobyanimation?changes=__2_2
FromToByAction → https://developer.apple.com/documentation/realitykit/fromtobyaction?changes=__2_2
As developer, when should we reach out to use an animation vs action ? 🤔
I am using Model3D to display an RCP scene/model in my UI.
How can I get to the entities so I can set material properties to adjust the appearance?
I looked at interfaces for Model3D and ResolvedModel3D and could not find a way to get access to the RCP scene or RealityKit entity.
I have looked here:
Reality View Documentation
Found this thread:
RealityView Update Closure Thread
I am not able to find documentation on how the update closure works.
I am loading attachments using reality view's attachment feature (really helpful). I want to remove them programmatically from another file. I found that @State variables can be used. But I am not able to modify them from out side of the ImmersiveView swift file. The second problem I faced was even if I update them inside the file. My debugging statements don't execute.
So exactly when does update function run. I know it get's executed at the start (twice for some reason). It also get's executed when I add a window using:
openWindow?(id: "ButtonView")
I need to use the update closure because I am also not able to get the reference to RealityViewAttachment outside the RealityView struct.
My Code(only shown the code necessary. there is other code):
@State private var pleaseRefresh = ""
@StateObject var model = HandTrackingViewModel()
var body: some View {
RealityView { content, attachments in
if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
content.add(immersiveContentEntity)
}
content.add(model.setupContentEntity())
content.add(entityDummy)
print("View Loaded")
} update: { content, attachments in
print("Update Closure Executed")
if (model.editWindowAdded) {
print("WINDOW ADDED")
let theattachment = attachments.entity(for: "sample")!
entityDummy.addChild(theattachment)
// more code here
}
}
attachments: {
Attachment(id: "sample") {
Button(action: {
model.canEditPos = true
model.canRotate = false
pleaseRefresh = "changed"
}) {
HStack {
Image(systemName: "pencil.and.outline")
.resizable()
.scaledToFit()
.frame(width: 32, height: 32)
Text("Edit Placement")
.font(.caption)
}
.padding(4)
}
.frame(width: 160, height: 60)
}
}
How can the update method (or the code inside it) run when I want it to?
I am new to swift. I apologize if my question seems naive.
I can‘t Figure Out How to Get My Earth Entity to Rotate on its Axis. This is a follow up post from a previous Apple Developer forum post.
How would I have the earth (parent) entity rotate CCW underneath the orbiting starship child?
I tried adding the following code block to the RealityView but it is not working:
if let rotatingEarth = starshipEntity.findEntity(named: "Earth") {
rotatingEarth.transform.rotation = simd_quatf.init(angle: 360, axis: SIMD3(x: 0, y: 1, z: 0))
if let animation = try? AnimationResource.generate(with: rotatingEarth as! AnimationDefinition) {
rotatingEarth.playAnimation(animation)
}
}
Any advice on getting the earth to rotate?
I tried reviewing the Hello World WWDC23 project code, but I was unable to understand the complexity and how that sample project got the earth to rotate.
i want to do this for visionOS 1.2. I realize there are some new animation and possible other capabilities coming up in vision 2.0 but I want to try to address this issue in the current released visionOS version.
In RealityKit using visionOS, I scan the room and use the resulting mesh to create occlusion and physical boundaries. That works well and iI can place cubes (with physics on) onto that too.
However, I also want to update the mesh with versions from new scans and that make all my cubes jump.
Is there a way to prevent this? I get that the inaccuracies will produce slightly different mesh and I don’t want to anchor the objects so my guess is I need to somehow determine a fixed floor height and alter the scanned meshes so they adhere that fixed height.
Any thoughts or ideas appreciated
/Andreas