How to manage collision events to save performance

I’m making a wall climbing ability in my game, and this will require events which detect the player’s collision with the platforms.


These are the conditions which trigger the ability. When I looked at the profiler, this whole event group takes up around 0.3~0.5 ms, which is quite a huge number for a single ability. The current total ms in my game is over 10, and I believe it is due to the abusive use of collision detection between numerous objects. The same theory applies to the attack detection which takes up 0.8 ms. Is there a way to use collision detection more efficiently? Like, putting them under several conditions as a sub event, or is there a way to avoid using this condition?

WRT the animation checks, you could create a boolean variable name “`canClimbWalls”, and set it to true whenever you set the animation to those in that condition, and false otherwise. The you’d only need to check the boolean value, rather than comparing the string multiple times.

Alternatively, you could put all the animation names in a comma delimited variable string, and check if the variable string contains the animation name. That may be a tad faster.

1 Like

I used a similar approach when doing the attack detection. When enemies are hit, a variable of the enemies called “attacked” is toggled to true, and when this variable is true, other subsequent actions are triggered. But I doubt if this will really be more efficient, since the same number of events, even more events are run, and there is a new intermediate variable used.

It may have an impact. Instead of referencing the animation name and comparing it multiple times, the boolean is set once when the animation changes because of other conditions. Changing or comparing a boolean will be much faster than comparing a lot of strings. Not sure how much of an improvement it will make, but I like to be surprised.

Ok. Thanks! I’ll try.