iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🏃

Where Should RealityKit.System.register() Be Called?

に公開

I was curious about where System.register() should be called, so I looked into it.
Looking at Apple's "Building an Immersive Experience with RealityKit" sample code, register was called during the AppDelegate startup process.

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

In "Creating a spatial drawing app with RealityKit", it was called within the make of RealityView.

https://developer.apple.com/documentation/realitykit/creating-a-spatial-drawing-app-with-realitykit

In the same project, it was also called in the init of a model class.

There doesn't seem to be a unified official guideline on where to call it.
Generally, I think it's best to call it in a location that is executed only once.
It might be better to avoid SwiftUI's init or onAppear, as they can be called multiple times.

Discussion