My Box2D code has a bunch of objects moving about on the screen and for reasons I can't explain, beginContact is invoked regardless of sensor enabled or disabled.
In other words, fixture.setSensor(false) triggers the beginContact and that is counter-intuitive. Infact, with further debugging, I do this:
local function beginContact(a, b, coll)
local aindex = a:getUserData() -- this is simply a handle/index to the global array
local bindex = b:getUserData()
print(PHYS_PLAYERS[aindex].fixture:isSensor(), PHYS_PLAYERS[bindex].fixture:isSensor())
...
The majority of the time (not not every time), isSensor = false on a and b. What am I not understanding? Why is a collision created when sensor = false?
If I understood the problem correctly, the difference between a sensor and a non-sensor fixture is that sensors generate collision callbacks but they don't generate a physical collision response. From what I understand in your case you expect beginContact to be called only when the fixtures are sensors so if you need to differentiate between sensor and non-sensor fixtures in your beginContact callback you can just use the fixture:isSensor() method to check if each device is a sensor or not.
Sensors do not cause collision responses (they pass through other objects instead of bouncing off), but the beginContact and endContact World callbacks will still be called for this fixture.
Is a sensor on a fixture even needed to trigger beginContact?
No.
Maybe it is the word "sensor" that confuses you?
It means the body will not physically collide with other bodies but you will still get the callbacks if they overlap.
Example usage, a photoelectric barrier: If player walks through this area then open a door.
The player should not bounce of a photoelectric barrier or be blocked from moving through a radar screen or similar. But the collision callback functions will still be called so that the game can trigger some response.