title: SpriteKit: No Collision Detection between Sprites.
body: <p>Setting up collision detection in SpriteKit shouldn't be a difficult endeavour, and I've done it before. Yet despite using it successfully in other projects and the abundance of documentation on the topic, I can't get it to work in my current project, and I don't know why. </p>
  
  <p>The context is pretty Simple. I am adding spheres (SKSpriteNode) to a background Sprite, and then moving them with my finger expecting them to detect collisions when they touch each other. (Which does not happen). </p>
  
  <p>The intended outcome is that collision is detected. </p>
  
  <p><strong>Scene Setup:</strong> </p>
  
  <pre><code>@interface GameScene () &lt;SKPhysicsContactDelegate&gt;
  ...
  @implementation GameScene
  
  // Collision BitMask
  static const uint32_t planetCategory =  0x1 &lt;&lt; 0;
  </code></pre>
  
  <p>The Scene also sets itself as the delegate for physicsWorld</p>
  
  <pre><code>[self.physicsWorld setContactDelegate:self];
  </code></pre>
  
  <p>I've given my scene just one Collision bitmask, because all objects are of the same type and should all hit each other. I have also set the scene to comply to the SKPhysicsContactDelegate protocol. </p>
  
  <p><strong>Sprite Configuration:</strong></p>
  
  <pre><code>#pragma mark Protocol Methods (For Adding Planets)
  -(void)addSKPlanetDescriptorObject:(SKPlanetDescriptor *)object
  {
      if (self.allowedNodes &gt; 0){
  
          SKObject *node = [[SKObject alloc]initWithImageNamed:object.imageName];
          [node setDescriptor:object];
  
          // Set Physics
          [node.physicsBody setCategoryBitMask:planetCategory];
          [node.physicsBody setContactTestBitMask:planetCategory];
          [node.physicsBody setCollisionBitMask:planetCategory];
  
          [self.background addChild:node];
          [self.sceneObjects addObject:node];
          [node setPosition:self.pendingSpawnPoint];
          [self decreaseObjectCount];
      } else {
          [self indicateMinObjectCount];
      }
  }
  </code></pre>
  
  <p>And finally, the initializer used for <em>SKObject</em>, a subclass of <em>SKSpriteNode</em></p>
  
  <pre><code>@implementation SKObject
  
  
  -(instancetype)initWithImageNamed:(NSString *)name
  {
      self = [super initWithImageNamed:name];
      if (self)
      {
          [self setPhysicsBody:[SKPhysicsBody bodyWithCircleOfRadius:self.size.width/2]];
          [self.physicsBody setAffectedByGravity:NO];
          [self.physicsBody setUsesPreciseCollisionDetection:YES];
          [self.physicsBody setDynamic:YES];
          [self.physicsBody setMass:1000];
      }
      return self;
  }
  </code></pre>
  
  <p>I've tried removing the setPhysicsBody methods outside of the init statements, I've tried changing the bitmask, I've tried omitting setCollisionBitmask and more, but I simply cannot figure out why I'm not getting any collisions.</p>
  
  <p>I've also added</p>
  
  <pre><code>-(void)didBeginContact:(SKPhysicsContact *)contact
  {
      NSLog(@"Did Begin Contact");
  }
  </code></pre>
  
  <p>With a line break to notify me if anything is detected. But this method never gets fired.</p>