2

I wondered if there was an easy way to see a list of all actions currently assigned to a node in SpriteKit. Something like an "actions" property that will contain a list of all a node's actions. The documentation for SKNode does not show anything like this.

However, I put a breakpoint in the Xcode debugger and saw that indeed there was an actions property on my SKNode:

debugger screenshot

You can see in the debugger that this actions array contains two actions that are running on my node. But strangely, if I try to access that property in code I get an error:

let node = self as SKNode
print(node.actions)
// Value of type 'SKNode' has no member 'actions'

Can anyone tell me where this actions property on the SKNode is coming from? Why can we see it in the debugger but cannot access it in code?

peacetype
  • 1,928
  • 3
  • 29
  • 49
  • I am just curious, how would you use that property? – Whirlwind Mar 08 '22 at 06:19
  • In my case, I was debugging and I wanted to print a list of the node's current actions to the console at regular intervals so I could confirm that things were happening as expected. In production code... I'm not sure how off the top of my head. But I'm sure it would have its uses. You might get the `count` of that array to ensure that it doesn't have more than X number of actions before adding a new action to the node. Probably other uses if I keep thinking about it. But now my curiosity is piqued. I want to know why there seems to be a "hidden property" that I can't access in code. Seems odd. – peacetype Mar 08 '22 at 07:40
  • Ok well, its not that I am trying to negate that this would be cool to have, but number of actions on a node that are currently running IMO have no use. Actions, if written correctly can be run in very large amout without FPS drops. When it comes to debugging ok, but still we can see that in debugger as you have shown, or grab them by key. But ok yeah, interesting thing you have noticed here :) – Whirlwind Mar 08 '22 at 14:03
  • @Whirlwind Yeah, probably more useful in debugging than anything. It would be far more convenient to log this information to the console automatically than to keep hitting a breakpoint every frame. – peacetype Mar 08 '22 at 18:23

0 Answers0