Double SpriteKit scene loading of custom scene class from scene editor archive

Originator:kevin
Number:rdar://29090190 Date Originated:11/3/2016
Status:Open Resolved:
Product:iOS SDK Product Version:10.1
Classification:Serious Bug Reproducible:Always
 
When loading a SpriteKit scene from a scene archive with a custom scene class specified (as is the case with the game template), the scene's sceneDidLoad() function is called twice, but the documentation says it is called once and should be used for one-time initialization.

Reproduction Steps:
1. Open the attached project, or create a new game template.
2. Add a print statement / debug breakpoint in to GameScene.sceneDidLoad()

Expected:
The print/debug is hit once, per the documentations for the function: "This is called once after the scene has been initialized or decoded, this is the recommended place to perform one-time setup"

Actual:
The print/debug is hit twice. The attached project includes a StackTraces.rtf that shows the 2 paths. It appears that the first call happens because of a nested call to SKScene.init(coder:) through SKNode, and the second call happens in the main SKScene.init(coder:) that the .sceneWithFileNamed() helper uses in initialization.

Since one-time initialization is usually the heavier weight processes, having this occur twice is both unexpected in terms of already initialized variables, but also performance degrading because of the unnecessary operations. It is also unclear whether or not the entirety of the scene is really already loaded during the first call.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!