[LibGDX][Box2D] Body active for only one world step

I am trying to create a 2d RPG in LibGDX and I am using Box2D to handle interactions between the player, enemies, loot, etc.

My player currently has two bodies, one for his movement, and another for melee attack collisions. When the player presses attack, I want the attack body to become active for only one step so that it can interact with enemies for the first iteration and then become inactive until the player presses the attack button again. Specifically I do not want the body to stay active while the user holds down the attack button.

In Actor.act() I set the body to active when I first detect that the user is pressing attack, but I am not able to find a proper point to set the body inactive. I have tried disabling it in the second Actor.act(), but when I try that I get no collisions, I’m assuming because the Box2D and LibGDX time steps are not perfectly synced. I have also tried setting the body inactive after World.step(), but I also get no collisions there. Does a body need to be active for two steps to cause collisions?

I just tried adding a counter to the method that makes the body inactive after World.step(). If I require World.step() to be called 2 times before setting the body inactive, I seem to get collisions roughly 10% of the time. As I increase the step count, this probability becomes higher, but even at 10 steps, I still am not getting a collision 100% of the time. I need to be sure that World allows my body to collide for one iteration, otherwise the player will be frustrated that some of his attack have no effect.

I am not fully sure what the problem may be, but your approach to using two bodies for one actor and toggling between them seems risky: I have no idea if Box2D is capable of handling that.

Anyway, perhaps you could try replacing the shape instead of the whole body? That seems to be possible at least according to this link.