Loading a lighting resource for a RealityKit view on macOS - image not embedded in app bundle

I'm trying to load up a virtual skybox, different from the built-in default, for a simple macOS rendering of RealityKit content.

I was following the detail at https://developer.apple.com/documentation/realitykit/environmentresource, and created a folder called "light.skybox" with a single file in it ("prairie.hdr"), and then I'm trying to load that and set it as the environment on the arView when it's created:

let ar = ARView(frame: .zero)
do {
    let resource = try EnvironmentResource.load(named: "prairie")
    ar.environment.lighting.resource = resource
} catch {
    print("Unable to load resource: \(error)")
}

The loading always fails when I launch the sample app, reporting "Unable to load resource ..." and when I look in the App bundle, the resource that's included there as Contents/Resources/light.realityenv is an entirely different size - appearing to be the default lighting.

I've tried making the folder "light.skybox" explicitly target the app bundle for inclusion, but I don't see it get embedded with it toggle that way, or just default.

Is there anything I need to do to get Xcode to process and include the lighting I'm providing?

(This is inspired from https://stackoverflow.com/questions/77332150/realitykit-how-to-disable-default-lighting-in-nonar-arview, which shows an example for UIKit)

Answered by DTS Engineer in 800592022

Hello @heckj,

Can you provide a link to a focused sample project that reproduces the error? I just tried this process myself and I am seeing the correct lighting environment, so this issue may be specific to your project or resource.

Best regards,

Greg

Hello @heckj,

Can you provide a link to a focused sample project that reproduces the error? I just tried this process myself and I am seeing the correct lighting environment, so this issue may be specific to your project or resource.

Best regards,

Greg

After putting together the project, and thinking "Oh, I should try the released Xcode in case this is a regression...", I found that it is, in fact, a regression in Xcode.

I've updated the sample project - which now has a separate project built with Xcode 15.4, alongside the original which I started with Xcode 16b5 (and doesn't open in 15.4 because of that). When the same code and setup is built and run with Xcode 15.4, it works perfectly.

The project created in Xcode 15.4 compiles and runs correctly when built with Xcode 16 beta 5, but the project created in Xcode 16 beta 5 doesn't set up the correct structure or something, and doesn't embed the resource. (I've submitted feedback with the details : FB14860256)

It seems to be more related to a regression or change in Xcode 16 beta 5 vs Xcode 15.4 than that. In Xcode 15.4, it works perfectly, regardless of the name of the folder.

When I rename the file and compile in Xcode 16 beta, using either the new format Xcode project or old one, it doesn't appear to be loading correctly.

I've updated the sample project to change the name of the directory, but it doesn't appear to make a difference, and the product built by Xcode 16 still fails to include the resource and present it.

There appear to be perhaps multiple issues at play. After renaming the directory to prairie.skybox for this example - when the older Xcodeproj is built and run from Xcode 16, there's a different error reported - although the resource is correctly embedded:

Unable to load resource: Reality File version 11 is not supported. (Latest supported version is 9.)

It is all working - regardless of the name of the skybox directory - when built and run from Xcode 15.4.

@heckj,

I'm not sure what I'm missing here. You have updated the project you linked to incorporate my suggestion "skyboxSampleRealityKit.xcodeproj", and I just downloaded, built, and ran it with Xcode 16 beta 5, it worked correctly.

Best regards,

Greg

Loading a lighting resource for a RealityKit view on macOS - image not embedded in app bundle
 
 
Q