Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 9.1 (and 9.2) - Referenced sprites are not executing Actions added in Scene Editor

I have come across some unexpected behaviour when using the SpriteKit Scene Editor, and wonder if anyone else is having the same issue.

I created a sprite in a scene and added Actions to move it around using the Scene Editor. The Actions play fine when I click the animate button on the editor. I add a reference to this scene to the main scene using the SKReferenceNode object in the Scene Editor, and the sprite appears in the main scene as expected in the Editor. When I build and run the app however, the sprite appears but no Actions run. I have tried this on the Xcode 9.2 beta and get the same result. If I load the sprite scene directly from the main view controller, all the Actions execute as expected, so it seems to be an issue with referenced nodes. I also found that if I override didMove(to:) in the main scene swift class, and put a breakpoint in it, then just hit continue when it hit the breakpoint, all Actions play on referenced sprites as expected. If I disable the breakpoint, no Actions play on referenced sprites. (So my workaround is to simply use the breakpoint, and hit the continue button)

Another interesting observation. I opened a sample project created with an older version of Xcode, and referenced sprites executed their Actions fine. I copied this older SKS file into my project and Actions worked fine...until I edited the SKS file (added another Action), then they never worked again.

like image 698
Roger Avatar asked Dec 03 '17 06:12

Roger


2 Answers

I had this same problem and it was driving me crazy. I tried setting the .isPaused on the scene and on the individual sprites. Nothing worked except the insert breakpoint method. That is not a solution.

What I discovered was if I set the is paused to true and false (which is the value I wanted) then it worked for all the sprites.

 override func didMove(to view: SKView) {
    self.isPaused = true
    self.isPaused = false
}

This is a pretty annoying bug in scene editor that should be fixed.

like image 166
John McCaffrey theARTboy Avatar answered Jan 05 '23 02:01

John McCaffrey theARTboy


I asked a similar question just the other day: XCode 9: SKEditorReference doesn't allow animations?

The only way I was able to get this to work was to put the isPaused on the exact sprite node I was trying to animate (within a ref node - I had created an entire sks scene/file and drag-dropped that into my main scene).

I tried isPaused=false at the top level, main scene didMove to view to no effect, and then added isPaused=false to the main reference node, to no effect. It worked only when I added isPaused=false the actual sprite I was trying to animate. I removed isPaused=false from the the main & ref nodes, and as long as it was still on the sprite node (within the ref node) I was trying to animate: success.

Bottom line seems to be that isPaused=false is required on any sprites within a reference node.

like image 42
Eric Avatar answered Jan 05 '23 02:01

Eric