confusing performance

Discussion and feedback on Construct 2

Post » Sun Mar 01, 2015 12:30 pm

Thanks for the clarification, think that was greatly needed :D

However in what circumstances is the extra functionality of "On collision" a benefit or where is it intended to be used? At least in my experience I mostly used it with bullets hitting an enemy and then the bullet is destroyed. However you say that it needs to keep track of when the separation happens and touch again. Where as "Is overlapping" doesn't do this and just checks for an overlap, which is really what you need when a bullet hits an enemy for instant as the bullet most likely is destroyed.
Im a bit uncertain how to formulate the question :D, but can you give an example where "On collision" would outshine "Is overlapping" meaning where the extra functionality is obvious or what to say? or if anyone else can? I would appreciate it, because im happy with the clarification, but sadly I still don't see the reason to use "On collision" over "Is overlapping", so an example would help me?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Mar 01, 2015 7:29 pm

@nimos100

Colludium already gave an example of this earlier in the thread. Using Overlap + Trigger Once, you may run into a situation where the the original object overlaps a second object while still having already overlapped the first one earlier in time. When this happens, Overlap + Trigger Once will fail to trigger.

This limitation can get exacerbated if you make use of families: Obj1 Overlap Family + Trigger Once.

For example, you have a Farmer object, and a Fruit Family which consists of three different objects Apple, Oranges, and Caimitos.
Your collision routine is:
Code: Select all
Farmer Overlap FruitFamily + Trigger Once --> Spray the fruit with pesticide. (the fruit remains)


Here is a situation that might occur:
  • Farmer is walking quickly through the garden
  • Farmer overlaps an Apple
  • Overlap triggers and fruit is sprayed.
  • Farmer sprite is fairly large and overlaps an Orange
  • Since the farmer is still overlapping a FruitFamily (the apple), the overlap event will not be triggered.

So basically, the overlap will NOT trigger again until the farmer is not overlapping *ANY* FruitFamily objects. On collision does not have this limitation.
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Sun Mar 01, 2015 8:08 pm

@CrudeMik

the debug mode automatically ads 20% cpu utilization :) if its shows 40 fps or 10% cpu utilization dont worrie about it if you run an old rig (core duo or smth under i5)
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Sun Mar 01, 2015 10:51 pm

nimos100 wrote:Thanks for the clarification, think that was greatly needed :D

However in what circumstances is the extra functionality of "On collision" a benefit or where is it intended to be used? At least in my experience I mostly used it with bullets hitting an enemy and then the bullet is destroyed. However you say that it needs to keep track of when the separation happens and touch again. Where as "Is overlapping" doesn't do this and just checks for an overlap, which is really what you need when a bullet hits an enemy for instant as the bullet most likely is destroyed.
Im a bit uncertain how to formulate the question :D, but can you give an example where "On collision" would outshine "Is overlapping" meaning where the extra functionality is obvious or what to say? or if anyone else can? I would appreciate it, because im happy with the clarification, but sadly I still don't see the reason to use "On collision" over "Is overlapping", so an example would help me?


A beam weapon that expands and hits an enemy, then keeps going and hits more enemies.

If you use Is Overlap, it will trigger many times on each enemy hit. If you add Trigger Once to it, it sometimes does not trigger on the subsequent enemy hits so the AoE is not reliable.

Image

On Col works and trigger once for each instance and it will hit as many instance as it needs, but once only, very reliable.

The same applies for other AoE weapons, like an expanding nova or EMP circle, shockwaves, etc. On Col is 100% reliable.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Sun Mar 01, 2015 11:22 pm

@Silverforce
If you use Is Overlap, it will trigger many times on each enemy hit. If you add Trigger Once to it, it sometimes does not trigger on the subsequent enemy hits so the AoE is not reliable.


See my earlier explanation, it explains why this happens. It is expected behavior and by-design.

Bottom-line:
"On Overlap + Trigger Once" keeps track at a per-Object Type/Family Level.
"On Collision" keeps track at a per-UID level.
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Sun Mar 01, 2015 11:43 pm

cacotigon wrote:See my earlier explanation, it explains why this happens. It is expected behavior and by-design.

Bottom-line:
"On Overlap + Trigger Once" keeps track at a per-Object Type/Family Level.
"On Collision" keeps track at a per-UID level.


Yes, its good to now know the pros & cons of both approach, where possible, use Is Overlap with Trigger Once, or without it with bullets that destroy themselves etc, since On Col has added overhead and should be used where required.

I had not considered using Is Overlap because I've always went with On Col, but definitely in future, where Is Overlap works fine, that should be used to optimize the game. With lots of col checks, such optimizations leads to major performance gains.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,616

Post » Mon Mar 02, 2015 12:10 am

There's probably no performance difference between 'Is overlapping' and 'On collision' if you immediately destroy the object, since it then doesn't require any tracking since it doesn't exist any more. However you probably want to use 'On collision' for correctness since it picks instances for individual collisions. For example:

+ On collision between A and B
-> System: create explosion at A.X, A.Y
-> Destroy A
-> Destroy B

Note the use of a system action. This always works like you expect: an explosion is created with every collision.

+ Is A overlapping B
-> System: create explosion at A.X, A.Y
-> Destroy A
-> Destroy B

This has a nasty edge case: if two different A-B pairs overlap each other for the first time in the same tick, it will run the event with both pairs picked. The system action then runs once, creating only one explosion (and the A.X, A.Y expressions will return the position of just one of the two objects involved). Both sets of objects are correctly destroyed, but you only got one explosion. You can fix that again with "For each", but then you may as well just use "On collision".
Scirra Founder
B
400
S
237
G
89
Posts: 24,550
Reputation: 195,537

Post » Mon Mar 02, 2015 8:21 am

ok I see your points, appreciated, thanks for that
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Mon Mar 02, 2015 10:04 am

yes then its better to use "on collision" ...
but why the cpu usage drop to 20 % when we use is overlap instead of using on collisions
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests