Is dynamically chaging collision layers and masks inefficienct in terms of performance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cardoso
:warning: Old Version Published before Godot 3 was released.

I have a project that is a 2D Game with a “fake” 3D depth (like in the 90’s brawlers)

For collisions I was thinking if changing the characters/items (when they move) collision layers and masks would be a good solution.

But I am worried that it might be a problem in performance.

What do you think?

Why do you want to change them when they move? Is there a problem leaving them on?
I don’t see a problem in changing them, you can do stress-tests in your game and see if you get lag spikes.
The only thing to be careful about is that changing layers dynamically is not instant, it’s applied only the next frame due to the order in which Godot processes scripts and collisions.

Zylann | 2017-04-28 16:53

Because if the player moves up/down, for example, I would want to make him collidable with item/enemies on the same y axis plane. So I would change the player layer or mask to match the items’.

cardoso | 2017-04-28 22:38

Ah, yeah that makes sense. Well as I said, that should not cause performance problems. If you want to be sure, profile it :wink:

Zylann | 2017-04-28 22:41

:bust_in_silhouette: Reply From: MrMonk

don’t use the body itself to detect collisions, use a raycast (or more) that will detect all collision layers. to answer your question, that is going to slow down your game (more than I have expected)

Thanks! I did not test in my project, cause in the end I chose not to use the collision masks. But at least I know that it can be a performace issue.

cardoso | 2017-05-09 14:45