问题
I am working on a game in which a character runs along the screen and the camera is following the character. For each scene I add all the required assests and place them on scene. I do this behind a loading screen, because SceneKit needs some time to put all the stuff on scene. After like 5 seconds I fade out the screen (which is basically a black UIImage that lays in front of everything) and the game starts. Depending on the current scene, the amout of memory required is between 200MB and 500MB.
Everything runs fine and smoothly, till the character gets close to a new scene asset, (which was already put on scene) and that was placed initially outside the actual frustum of the camera. The character runs towards it, and in the moment in which the asses enters the bounds of the screen, the app stucks for a few frames (the larger the geometry asset, the more frames are dropped).
i.Ex. a Geometry of size 3MB with PBR Textures of 1.5MB in total will drop some 5 to 10 frames as soon as it gets in the frustum of the camera. This happens more or less for all upcoming assets. (no matter, if the asset is an OBJ, a DAE, or a converted SCN file)
There are no crashes, everything is okay, the game continues as expected, but I have these annoying dropouts.
When i.Ex the character dies and the same scene reloads (it reloads completely from scratch) everything runs smoothly the second time and afterwards. No framedrops anymore.
Why is this happen? Is there a way to tell SceneKit to "really" preload everything? (like when the same scene is loaded for the second time)
PS: I currently use a iPhone 11 Pro Max with iOS 14, Xcode 12.2. (I observed this aleady in earlier versions.)
来源:https://stackoverflow.com/questions/65179315/scenekit-stucks-for-a-few-frames-when-scngeometry-asset-gets-inside-frustum-of