VisionOS-newbie-Cannot read the file in RealityKitContent

When I use the create a resources function to read the audio file in the immersive.usda file, it doesn’t work. The compiler reports that it cannot find the file in the project. I tried to get the URL of the immersive.usda file when creating a new default project, but I couldn’t retrieve it either. Why is that? Maybe I’m missing some configuration steps?

The following of my code:

Hello -- try omitting the .usda extension in the from: parameter to AudioFileResource.

I also noticed that you are in an async Task. It is recommended to use the async variant of the AudioFileResource initializer when you are in an async context. Like:

let resource = try await AudioFileResource(named: primPath, from: "Immersive", in: realityKitContentBundle)

edit: Additionally, because QueryResult conforms to Sequence, you can replace:

// Before
scene.performQuery(Self.audioQuery).forEach { ambientAudioEntity in  ... }

// After
for ambientAudioEntity in scene.performQuery(Self.audioQuery) { ... }

That way, you can stay in an async context within the loop body.

VisionOS-newbie-Cannot read the file in RealityKitContent
 
 
Q