StaticBody2D Collision Mask has no effect on CharacterBody2D

Godot Version

4.2

Question

I have a CharacterBody2D for my player, and a StaticBody2D for a wall which I want my player to move_and_slide() against.

It is my understanding that as long as there is a collision layer N such that

  1. the player is on layer N and the wall scans for N (N is in the wall’s mask)
    or
  2. the player scans for N and the wall is on layer N
    then, a collision will happen and the player will not go through the wall.

However, I am finding that only situation 2 results in a collision. To be more clear, here is roughly what I have tried in my scene

Experiment 1:
player layer:1 mask:NA
wall layer:NA mask:1
Result: player goes right through the wall

Experiment 2:
player layer:NA mask:1
wall layer:1 mask:NA
Result: player slides against the wall as desired

So, is this intended behavior? If so, what is the purpose of the collision mask for staticBody2D’s?

I was hoping to not set any mask for the player and let walls handle collision with the player so that I would later have the freedom to create a purely visual wall that the player doesn’t collide with can go right through while still interacting with other objects such as enemies. As it is, such a feat (I think) would require adding a new layer for that object and specifying how each of the other objects in the game interact with it through their masks (a pain)

To eliminate some common problems:

  • both the player and wall have collision
  • the player is being moved each frame exclusively with calls to move_and_slide(). I’m not setting position directly ever