I am porting some of my code from SceneKit to swiftUI, and am trying to figure where to extract the SceneView instance's AVAudioEngine, as was the case when using IBOutlet. Looking at the documentation, I can't find a way to go into properties. SceneView conforms to View, but on content load, this does not seem to be evident.
I just spent a few hours porting a large code base to fit with this on a research project I am leading, and would like to figure this out rather swiftly :)
Thanks for any help
Hello,
Unlike SCNView, SceneView does not conform to SCNSceneRenderer, and does not provide you with a reference to the underlying SCNSceneRenderer. The SCNSceneRenderer holds a reference to the AVAudioEngine, so you will need to get a reference to the underlying scene renderer.
Technically, you can do this and still use SceneView, but you will need to provide a SCNSceneRendererDelegate object in the SceneView initializer, and then you can obtain the reference to the SCNSceneRenderer from one of the delegate method callbacks, and from there you can access the AVAudioEngine. I don't necessarily recommend this approach, but it should work.
The other approach, (and this is what I would recommend you do) is to create your own UIViewRepresentable container for SCNView. If you create the container, you get to decide what SCNView/SCNSceneRenderer properties to expose :)