DEPRECATED


Something has changed from r130 (when this was first tested) to the current release of Construct. This performance trick is no longer applicable. A Family-To-Family collision event routine NOW performs the same number of collision checks as separate Object-To-Family checks. It appears that redundancy checks are no longer performed.




One very important reason to take every effort to reduce the number of collision-related events is related to how Construct handles collision detection. Construct's engine does not cache collision detection. What this means is that any time you do an Overlap or Collision detection event, it will recheck all objects related to that event even if you might have compared some of the objects before.
Let's take an example:

You have a family called BoxFamily with three object types, GreenBox, PinkBox, and YellowBox. On the actual layout, you have one instance of each object. In order to be able to distinguish between the two objects involved in the collision, you might assume you can just write three collision checks from object to family, like so:

boxtofamily.png

Every game cycle, it would execute the following:

  • GreenBox On Collision with Family - Two separate collision checks: GreenBox-PinkBox and GreenBox-YellowBox
  • PinkBox On Collision with Family - Two separate collision checks: PinkBox-GreenBox and PinkBox-YellowBox
  • YellowBox On Collision with Family - Two separate collision checks: YellowBox-GreenBox and YellowBox-PinkBox

For a total of 6 collision checks.

Not let's see what would happen if we used a single Family to Family collision event, as in the following:

boxfamilytofamily.png

Every game cycle, it would run the following check:

  • Collision Check: GreenBox-PinkBox (the same as PinkBox-GreenBox)
  • Collision Check: GreenBox-YellowBox (the same as YellowBox-GreenBox)
  • Collision Check: PinkBox-YellowBox (the same as YellowBox-PinkBox)
  • Collision Check: PinkBox-PinkBox
  • Collision Check: YellowBox-YellowBox
  • Collision Check: GreenBox-GreenBox




Allowing us to half the number of collision checks! For a concrete example of this kind of performance gain in action, see the attached Benchmarking Capx. Click the buttons to switch between the types of collision detection, and hold the right-mouse button down in the layout to increase the number of boxes.