SpriteKit Scene Editor actions bug

I have two sks files, one with nodes and another with actions both created in Scene Editor. I want to load nodes and add them to another node and then apply actions to them, something like:


override func sceneDidLoad () {

    let heroScene = SKScene(fileNamed: "Hero")
    let head = heroScene?.childNode(withName: "HeroHead") as! SKSpriteNode
    let testAction = SKAction(named: "HeroTestAction") as! SKAction
    let loop = SKAction.repeatForever(testAction)
    let hero = SKSpriteNode(color: SKColor.white.withAlphaComponent(0) , size: CGSize(width: 50, height: 250)
    let body = SKSpriteNode(color: SKColor.blue, size: CGSize(width: 50, height: 50))

    head.removeFromParent()
    hero.addChild(head)
    hero.addChild(body)
    self.addChild(hero)

    head.run(loop)
    body.run(loop)
}


But action does not apply to

head
. If i apply loop to
body
or
hero
it works.

Later i found when first time run example, action not works, but if close app and run again it is works, as it shown here: https://stackoverflow.com/questions/49083914/how-to-load-nodes-from-sks-file-and-then-apply-action-defined-in-scene-editor

Replies

Looks like this could be the problem....


head.removeFromParent()


You know you can parent the head to the hero within the Scene Editor right?