A simple, reusable animation that changes attributes of any node you attach it to.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
You use actions most often to change the structure and content of the
SCNNode object to which they are attached, but you can also use actions make other changes to the scene. In SceneKit, actions provide an easy way to implement animated behaviors that frequently change in response to user input.
Working with Actions
To create an action, call the class method for the action you are interested in. Then, configure the action’s properties. Finally, to execute the action, call a node object’s
run method (or a similar method from the
SCNActionable protocol) and pass it the action object.
Most actions allow you to change a node’s properties, such as its position, rotation, or scale. Many of these actions are animated by SceneKit, meaning that they change the properties of the associated node over more than one frame of animation rendered by the scene. When an action is animated, the
duration property states how long that action takes to complete in seconds and its
timing property defines the rate at which the animation executes. The action’s
speed property allows you to adjust the timing of the animation by increasing or decreasing its playback speed.
Many actions can be reversed, allowing you to create another action object that reverses the effect of that action. For example, if an action object moves a node
20 units in the positive X direction of its parent’s local coordinate space, the reversed action moves the node
20 units in the negative X direction. To create a reversed action object, call an action object’s
Some actions include other actions as children:
A sequence action has multiple child actions. Each action in the sequence begins after the previous action ends.
A group action has multiple child actions. All actions stored in the group begin executing at the same time.
A repeating action stores a single child action. When the child action completes, it is restarted.
You can nest groups, sequences, and repeating actions. By combining actions together, you can add sophisticated behaviors to a node.
Using Actions for Scene Animation
Actions are easily reused, can be added and removed while running, and directly affect presented nodes. For these reasons, actions work well when your scene changes frequently in response to user input—such as when building a game. Not all elements of a scene can be animated using actions. For other kinds of animation, use implicitly animated object properties (see the
SCNTransaction class) or explicitly created Core Animation objects (see the
SCNAnimatable protocol), or change the scene graph directly for each rendered frame (see the
You never subclass
SCNAction directly. Instead, create actions that call methods on arbitrary objects or execute blocks of code. See Creating Custom Actions.