A mechanism for creating implicit animations and combining scene graph changes into atomic updates.


@interface SCNTransaction : NSObject


You use SCNTransaction class methods to control the animation that results from changing animatable properties in the scene graph and to combine sets of changes into nested transactions.

Adding Animation with Automatic Transaction

SceneKit creates a transaction automatically whenever you modify the objects in a scene graph. This transaction groups any additional changes you make from the same thread during the current iteration of that thread’s run loop. When the run loop next iterates, SceneKit automatically commits the transaction, atomically applying all changes made during the transaction to the presentation scene graph (that is, the, version of the scene graph currently being displayed).

Because an automatic transaction has a default duration of zero, any changes it contains appear instantly when SceneKit automatically commits the transaction. By using the setAnimationDuration: method to change the duration, you implicitly animate all changes made to animatable properties during the transaction. You can use implicit animation to add animation to a scene quickly and easily. For example, the code in Listing 1 fades out and moves one node, fades in another, moves and zooms the point of view camera, and focuses a spotlight, all in a single one-second animation.

Listing 1

Implicitly animating several property changes

[SCNTransaction setAnimationDuration:1.0];    
_textNode.position = SCNVector3Make(0.0, -10.0, 0.0);
_textNode.opacity = 0.0;
_heroNode.opacity = 1.0;
view.pointOfView = _heroCamera; = 20.0;
_lightNode.light.spotInnerAngle = 30.0;

Creating Advanced Animations with Custom Transactions

You can also use SCNTransaction class methods to create and manage a hierarchy of your own transactions. By nesting custom transactions, you can group sets of scene graph changes, applying different animation parameters to each group. Use the begin method to create a custom transaction, nested within the current transaction if one exists. Use the commit method to end a transaction, applying all scene graph changes made within.


Creating and Committing Transactions

+ begin

Begins a new transaction for the current thread.

+ commit

Commits all changes made during the current transaction.

+ flush

Applies all changes from the current automatic transaction.

Overriding Animation Duration and Timing


Returns the duration, in seconds, of all animations within the current transaction.


Returns the timing function that SceneKit uses for all animations within this transaction group.

Temporarily Disabling Property Animations


Returns a Boolean value indicating whether changes to animatable properties during the transaction are implicitly animated.

Getting and Setting Completion Block Objects


Returns the block previously associated with the current transaction.

Managing Concurrency

+ lock

Attempts to acquire a recursive spinlock to ensure the validity of values you retrieve during the transaction.

+ unlock

Relinquishes a previously acquired transaction lock.

Getting and Setting Transaction Properties

+ setValue:forKey:

Associates an arbitrary object with the current transaction using the specified key.

+ valueForKey:

Returns the object previously associated with the current transaction using the specified key.


Inherits From