What's better for performance...

I have a body that is the main “character.” I then have multiple small bodies that it “collects” (you know, like gems or something like that for extra points). There are then many other bodies also. Now, I was wondering–Which option is better for performance:

  1. Put a preCollision event handler on the “character” that interacts with multiple other objects?
    or
  2. Put a preCollision event handler on the multiple “collectors’ items” that interact only with the “character”?

So basically have one body with multiple collision calls or multiple bodies with few collision calls?

Thanks! Sorry if that was confusing. [import]uid: 36022 topic_id: 13154 reply_id: 313154[/import]

I believe that using one body with a couple of collision calls is better than giving every single item you spawn a listener for a collision event :wink: [import]uid: 52491 topic_id: 13154 reply_id: 48326[/import]

preCollision events are much more processor intensive since they tend to get triggered much more frequently than regular collision events so you should use as few as possible. It would be better performance wise if you were able to use regular collision events instead if possible. [import]uid: 27965 topic_id: 13154 reply_id: 48344[/import]

Yes, @calebr2048 is right on! To give you a sense of scale, I’ve seen apps where preCollision events occurred 10,000 times as often as a regular collision event — for just one single render pass (it’d repeat for the next render pass) [import]uid: 26 topic_id: 13154 reply_id: 48355[/import]

Hmmmm…Thanks for the thoughts. I think I need a preCollision event because from the docs it sounds like that is the only place to make isSensor=true and allow the object to pass through the other without a hiccup. Am I right about this? [import]uid: 36022 topic_id: 13154 reply_id: 48426[/import]

Thanks for the replies! [import]uid: 36022 topic_id: 13154 reply_id: 48427[/import]

I tested my own theory and it seems like you can pass isSensor in the onCollision event handler. So I am going to drop the preCollision handler and go ahead with that. Thanks! [import]uid: 36022 topic_id: 13154 reply_id: 48429[/import]