I’m having leak problems with GKStateMachine. My App is a pretty straight code to test the problem. This is the GameScene:
import SpriteKit
import GameplayKit
class GameScene: SKScene {
lazy var gameState:GKStateMachine = GKStateMachine(states: [Introduction(scene: self)])
override func didMove(to view: SKView) {
self.gameState.enter(Introduction.self)
}
}
And this is my state:
import SpriteKit
import GameplayKit
class Introduction: GKState {
unowned let scene:GameScene
init(scene:SKScene) {
self.scene = scene as! GameScene
super.init()
}
override func didEnter(from previousState: GKState?) {
print("INSIDE THE Introduction STATE")
}
}
The problem is that when I run the Leaks debugger, I received one leak as soon as I enter to the state. Does anybody has a suggestion?
You can simplify the constructor to avoid the type cast.
init(scene: GameScene) {
self.scene = scene
super.init()
}