title: How to set up an ID system for enemies in Sprite Kit?
body: <p>I'm in the process of making a 2d Space Shooter style game for iOS, and am having trouble creating an ID system for game elements and particularly enemies. </p>
  
  <p>The tutorial I am using only shows how to make enemies explode after only one hit. It uses a function called didBegin(_ contact: SKPhysicsContact). </p>
  
  <p>This function, from my understanding, evaluates each instance of contact, assigns two bodies two distinct roles, and then decides what to do with each body. I assume to have an enemy take three hits, a variable containing their remaining health would be used. Then, with each instance of contact, the variable would decrease by one, until if it is zero, the enemy is removed.</p>
  
  <p>However, there is a deep problem in this. SincedidBegin(_ contact: SKPhysicsContact) evaluates only one instance of contact, it has no knowledge of other previous instances of contact. Essentially, when an enemy gets hit, there is no way to know if the enemy was hit before, has not been hit at all, or has been hit too many times. If there was only one enemy, then I could use one variable to keep track of its health. This is not the case, though, as there are multiple enemies on screen at once, and every time contact is made, there is no way to know if the previous hit was on this enemy, or another enemy.</p>
  
  <p>If there is one enemy on screen, it is simple because every time contact is made it would have to be that one enemy. But if there are multiple entities on screen, then there is no way to know which enemy a contact applies to.</p>
  
  <p>I know I must set up an ID system to be called after contact has been detected, I am just not sure how to do it.</p>
  
  <p>I have tried to set up a dictionary and a class structure (I know you can do solve it like this but I haven't been able to figure it out).</p>