ARKit addChildNode freezes SCNSceneView

Hi,
I have a working SCNSceneView on my screen and what I'm trying to do is to dynamically load on screen a .scn file.
I'm currently performing the following:
Code Block language
if let node = SCNReferenceNode(url: url) {
node.load()
self.sceneView?.prepare([node], completionHandler: {  _ in
   self?.sceneView?.scene.rootNode.addChildNode(node)
print("added child node")
})
}


I've tried a lot of other iterations where I'm calling load or prepare on a background DispatchQueue but my conclusion is that no matter what I try addChildNode(node) will freeze the screen until it finishes it's operation.

Did you find a solution for this issue ?

Unfortunately, I have not heard of anyone who has found a workaround for this issue and the performance is still terrible in today's iOS 14.5 Beta 3 and macOS 11.3 Beta 3 builds. 

The cause of the problem seems to be that SceneKit is (re-)compiling a 4,500 line Metal shader program every time you add a node or light to a scene. MetalKit appears to do the compilation with the GPU but SceneKit invokes MTLDevice.makeLibrary synchronously in a CADisplayLink handler so it actually hangs the whole app UI for about 200-400 msec each time you invoke .addChildNode. The result is app hangs of many seconds if you add multiple model nodes to a scene.

MetalKit caches the compilations in the file system, so if your app doesn't change anything, you might get lucky and avoid the hang in future .addChildNodes of the same model, but there seem to be numerous reasons the cache misses or is flushed.

See this earlier Forum thread for more discussion of this problem.
ARKit addChildNode freezes SCNSceneView
 
 
Q