Search code examples
sprite-kitskactionsknode

Do SKActions run when the respective node is hidden or not in the scene?


Do SKActions run when the respective node is hidden or not in the scene?

Scenario

I have a node with an SKAction added to it which repeats forever. This node is usually hidden however. I am wondering if SpriteKit rendering engine processes this Action and/or if its a performance hit (even in the slightest). In other words, is it advised that I remove this Action even though its node is hidden?


Solution

  • If the node is not in the scene it will not run, because the node is no longer on the scenes timer, but if it is hidden and in the scene it will run, otherwise you would not be able to do things like the fade in action.

    In your scenario, it all depends on what is going on. If you find yourself not needing the action, then do not use it. Will it affect performance? Of course, because you are wasting cycles. Will it be noticeable? At first no, but if you do a lot of this behavior then it becomes noticeable, so it is best to train yourself early to handle this problem.