title: SceneKit animation doesn't play in iOS
body: <p>I have an example of animations fully working for OS X, start, pause, change speed etc.</p>
  
  <p>Now I started porting this to iOS and can't even start the animation. I simplified the code to a minimum - it works in OS X, but not on iOS.</p>
  
  <p>What I do is</p>
  
  <ol>
  <li>Show a scene with a (animated) character in it (idle animation) - works both in OS X and iOS</li>
  <li>Start a run animation on the character. This works on OS X, run animation starts and loops. On iOS the character is positioned at the start of run animation. But it doesn't run...</li>
  </ol>
  
  <p>If I start with e.g. run scene instead of idle, it works - character runs. The problem is when I start an animation (any) after the scene is loaded. It loads the model with the animation but doesn't play.</p>
  
  <p>After detailed comparison between the OS X and iOS version I found 2 differences, which probably are related but I can't figure out how fix them:</p>
  
  <ol>
  <li><p>In the OS X version the character is not animated until I start an animation. In the iOS version when I attach the nodes from the idle (or whatever other) scene to the root, it's animated. I don't know how to change this.</p></li>
  <li><p>The OS X version has the scene.dae attached to the Scene View in the Storyboard - this is also the case in iOS. But in iOS for some reason this attachment is not working, ´self.scene´ is nil. This is why I have to instantiate and assign the scene programmatically. I couldn't fix it, tried re-adding the Scene View, assigning the outlet etc.</p></li>
  </ol>
  
  <p>The scene kit view is added using storyboard. idle and run are .dae files. Each of them contains a full model with the character, and the animation. I just double checked that the animation identifiers are the same as in the .dae files. The models are actually provided in an example from Apple and work perfectly on OS X...</p>
  
  <p>This is the code:</p>
  
  <p>View controller:</p>
  
  <pre><code>#import "ViewController.h"
  
  @interface ViewController ()
  
  @end
  
  @implementation ViewController
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  }
  
  - (void)viewDidAppear:(BOOL)animated {
      [self.sceneView loadScene];
  
  }
  
  @end
  </code></pre>
  
  <p>Scene kit view header:</p>
  
  <pre><code>//  ASCView.h
  
  #import &lt;UIKit/UIKit.h&gt;
  #import &lt;SceneKit/SceneKit.h&gt;
  
  
  
  
  @interface ASCView : SCNView
  
  
  
  - (void)loadScene;
  
  
  @end
  </code></pre>
  
  <p>Scene kit view implementation:</p>
  
  <pre><code>//
  //  ASCView.m
  //  anim_test
  //
  //
  
  #import "ASCView.h"
  
  @implementation ASCView
  
  - (void)loadScene {
  
      self.backgroundColor = [UIColor blueColor];
  
      self.allowsCameraControl = YES;
  
      [self loadSceneAndAnimations];
  }
  
  
  #pragma mark - Animation loading
  
  - (void)loadSceneAndAnimations {
      // Load the character from one of our dae documents, for instance "idle.dae"
      NSURL    *idleURL   = [[NSBundle mainBundle] URLForResource:@"idle" withExtension:@"dae"];
      SCNScene *idleScene = [SCNScene sceneWithURL:idleURL options:nil error:nil];
  
      SCNScene *scene = [SCNScene sceneNamed:@"scene.dae"];
      self.scene = scene;
  
      NSLog(@"scene: %@", self.scene);
  
      // Merge the loaded scene into our main scene in order to
      //   place the character in our own scene
      for (SCNNode *child in idleScene.rootNode.childNodes)
          [self.scene.rootNode addChildNode:child];
  
      // Load and start run animation
      // The animation identifier can be found in the Node Properties inspector of the Scene Kit editor integrated into Xcode
      [self loadAndStartAnimation:@"run" withIdentifier:@"RunID"];
  
  }
  
  - (void)loadAndStartAnimation:(NSString *)sceneName withIdentifier:(NSString *)animationIdentifier {
      NSURL          *sceneURL        = [[NSBundle mainBundle] URLForResource:sceneName withExtension:@"dae"];
      SCNSceneSource *sceneSource     = [SCNSceneSource sceneSourceWithURL:sceneURL options:nil];
      CAAnimation    *animationObject = [sceneSource entryWithIdentifier:animationIdentifier withClass:[CAAnimation class]];
  
  
      NSLog(@"duration: %f", [animationObject duration]); //0.9
  
      animationObject.duration = 1.0;
      animationObject.repeatCount = INFINITY;
  
  
      [self.scene.rootNode addAnimation:animationObject forKey:@"foofoofoo"];
  
      NSLog(@"animation: %@",[self.scene.rootNode animationForKey: @"foofoofoo"]);
      NSLog(@"is paused: %@",[self.scene.rootNode isAnimationForKeyPaused: @"foofoofoo"] ? @"yes" : @"no"); //NO
  }
  
  
  
  @end
  </code></pre>